This page has information on migrating your Dart 1.x web app to Dart 2. These changes are necessary because of the following:
-
Tooling changes:
- Chrome replaces Dartium and content-shell.
- A new build system replaces
pub build
,pub serve
, pub transformers.
- Dart 2 language and library changes.
Tools
The development environment for web apps is different in Dart 2 from Dart 1.x. Here are the highlights:
Dart 1.x | Dart 2 |
---|---|
Dartium, content shell | Chrome and the webdev tool
|
pub build |
webdev build |
pub serve |
webdev serve |
pub run angular_test |
dart run build_runner test -- -p chrome |
pub transformers | build package transformers. See: Transforming code |
Code
To migrate to Dart 2, you’ll need to edit your web app’s project files:
-
pubspec.yaml
. See details below. - HTML files with
<script src="foo.dart"...>
elements, such asweb/index.html
. See details below. - Dart code, due to changes in the Dart language and libraries.
For complete examples of migrating apps,
look at the files changed between the 4.x
and master
branches
of the following apps:
Pubspec
Make these changes to your pubspec.yaml
file:
- Add new
dev_dependencies
:build_runner:
-
build_test:
, if you are running tests build_web_compilers:
- Drop
dev_dependencies
:browser
dart_to_js_script_rewriter
- Upgrade to
test
version 0.12.30 or later; it runs Chrome tests headless by default. - Drop all
transformers
:angular
dart_to_js_script_rewriter
test/pub_serve
For example, look at the differences in the Quickstart example’s pubspec with these changes applied.
HTML with script elements
The most common example of a file with <script>
elements is web/index.html
.
You’ll need to make these changes:
- Drop
<script defer src="packages/browser/dart.js"></script>
- Replace
by<script defer src="foo.dart" type="application/dart"></script>
<script defer src="foo.dart.js"></script>
For example, look at the differences in the Quickstart example’s web/index.html page with these changes applied.
Additional resources
The Dart 2 migration guide has information about changes in Dart 2, and how to migrate your code from Dart 1.x.