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 <a href="https://www.dartlang.org/polymer-dart/" rel="nofollow">Polymer.dart</a> in my project. So, in my project root, I create the following
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
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.
According to the <a href="https://www.dartlang.org/docs/dart-up-and-running/contents/ch04-tools-dart2js.html" rel="nofollow">
dart2js docs</a>, I need to run something like:
dart2js --out=myapp.js --package-root=??? myapp.dart
<strong>How do I include all the browser & polymer packages on the buildpath?</strong>Answer1:
There is a "pub build" option now.
<a href="http://pub.dartlang.org/doc/pub-build.html" rel="nofollow">http://pub.dartlang.org/doc/pub-build.html</a><blockquote>
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.</blockquote>
$ 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.Answer2:
If you run dart2js from your
MyDartProject directory you don't have to provide
An alternative way is running
pub build. If you use Polymer you need to add a