Production Deployment

This chapter shows how to create tree-shaken, minified JavaScript that can run in any modern browser. It relies on the pub tool serve and build commands, both of which use a transformer provided by the angular package.

Specifying the angular transformer

Before you convert your AngularDart app to JavaScript, your app's pubspec.yaml file needs to specify the angular transformer:

For more information about transformers, see Pub Assets and Transformers.

Running the sample app

Once your app is working in Dartium, you're ready to test it in other browsers. We recommend starting with the pub serve command, either from the command line or from Dart Editor. Pub serve continuously monitors your app's assets, running transformers as necessary and serving up the transformed assets. Pub serve doesn't produce files; all of the transformed assets are in memory.

To run pub serve from Dart Editor, go to the Files view, right-click Chapter_06/web/index.html, and choose Run as JavaScript.

Dart Editor starts pub serve, displaying its output, and brings up the app in your default browser. Conversion to JavaScript might take half a minute. Once the app is available, you can test it in other browsers by copying the URL into them.

Supporting multiple browsers

Angular components use Shadow DOM, but unfortunately it’s not natively supported in all modern browsers, so you need to use a polyfill.

First, include the following script tags in the HTML <head> before any other script tags:

<script src="packages/web_components/platform.js"></script>
<script src="packages/web_components/dart_support.js"></script>

Or use the debug version:

<script src="packages/web_components/platform.concat.js"></script>
<script src="packages/web_components/dart_support.js"></script>

Note: Using the polyfill has some limitations, so make sure you are aware of those limitations before you start using it.

Generating deployable files

Use pub build to generate the app's files. You can run pub build either from the command line or from Dart Editor.

To run pub build from Dart Editor, go to the Files view, right-click the app's pubspec.yaml file, and choose Pub Build. The app's deployable files appear under a directory named build/web.