Dart Package Management via dart2js

时光毁灭记忆、已成空白 提交于 2019-12-23 15:37:25

问题


I'm learning Dart and its dependency manager pub and am having a tough time seeing the "forest through the trees" here.

Say I want to use Polymer.dart in my project. So, in my project root, I create the following pubspec.yaml:

name: test_dart
description: A sample web application
dependencies:
    browser: any
    polymer: ">=0.9.0 <0.10.0"

I then run pub get, which goes to the pub repo and fetches the browser and polymer dependencies that I've specified. It then creates a packages directory in my project root, which now means I have a project that looks like:

MyDartProject/
    pubspec.yaml
    myapp.dart
    packages/
        browser/
            ...
        ...all the packages that ship with Polymer

Now I start coding my Dart web app (myapp.dart), which will references various Polymer and browser types/functions/etc. in its source code.

When I'm all done, I want to create a JavaScript file called myapp.js.

According to the dart2js docs, I need to run something like:

dart2js --out=myapp.js --package-root=??? myapp.dart

How do I include all the browser & polymer packages on the buildpath?


回答1:


There is a "pub build" option now.

http://pub.dartlang.org/doc/pub-build.html

Use pub build when you’re ready to deploy your web app. When you run pub build, it generates the assets for the current package and all of its dependencies, putting them into a new directory named build.

$ cd ~/dart/helloworld
$ pub build
Building helloworld......
Built 5 files!

If the build directory already exists, pub build deletes it and then creates it again.

That should do everything you are after here. You can also launch it from the IDE by right clicking on the pubspec.yaml file and choose "pub build"

EDIT: You should also see the links in zoechi's answer.




回答2:


If you run dart2js from your MyDartProject directory you don't have to provide --package-root parameter.

An alternative way is running pub build. If you use Polymer you need to add a transformers section.

see also

  • How to deploy a Dart Polymer app to Javascript using dart2js
  • How do I pass multiple entry_points to polymer transformer in pubspec.yaml?


来源:https://stackoverflow.com/questions/20718955/dart-package-management-via-dart2js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!