Dart Package Management via dart2js


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 pubspec.yaml:

<pre class="lang-yaml prettyprint-override">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 <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>


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>


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.


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

<ul><li><a href="https://stackoverflow.com/questions/20398157" rel="nofollow">How to deploy a Dart Polymer app to Javascript using dart2js</a></li> <li><a href="https://stackoverflow.com/questions/20147030" rel="nofollow">How do I pass multiple entry_points to polymer transformer in pubspec.yaml?</a></li> </ul>


  • Fill value backwards from occurence by group
  • ruby - lazily iterate through an array
  • Composite Pattern Reuse For Different Types
  • ActionBar with appcompat library v7 (ava.lang.IllegalStateException: You need to use a Theme.AppComp
  • angularjs - ng-show doesn't update class when $interval triggers
  • Google cloud datastore emulator init data
  • docker-compose: connection refused between containers, but service accessible from host
  • “git push” doing the same as “git fetch” from the remote
  • SQLiteOpenHelper: onCreate() method not called on physical device
  • Launching a new command window from Golang in Windows
  • Enterprise Architect - Cancel Connectors Bridges
  • Getting proper map boundaries
  • Dependency Injection and Code Obfuscation
  • Why does this empty dict break shared references?
  • limited threads in soapUI free version
  • Spring Batch restart uncompleted jobs from the same execution and step
  • How can I stop my python script when another python script is running?
  • Delete std::shared_ptr without destroying the managed object?
  • How to send control C to Mac Terminal using python?
  • Granting permissions to Azure Active Directory Web Application automatically
  • Using MouseListener to select a range of cells in a grid
  • What Makes These Two Array Adds Different?
  • Android Database Error - getWriteableDatabase
  • Bigquery event streaming and table creation
  • pillow imaging ImportError
  • Cannot upload to OneDrive using the new SDK
  • Web.config system.webserver errors
  • Problems installing Yesod for Haskell
  • error importing numpy
  • Checking free space on FTP server
  • Change Inet root folder for iis 7
  • Cross-Platform Protobuf Serialization
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Updated Ionic CLI but shows previous version (Windows)
  • When should I choose bucket sort over other sorting algorithms?
  • How do you troubleshoot character encoding problems?
  • RestKit - RKRequestDelegate does not exist
  • Understanding cpu registers
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?