Skip to content

A pub transformer that Rewrites Dart script tags to JavaScript script tags, eliminating 404s and speeding up initial loads. Use when building for deployment.

License

Notifications You must be signed in to change notification settings

Workiva/dart_to_js_script_rewriter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

3cbdc4a · Sep 10, 2018

History

76 Commits
Feb 2, 2016
Feb 4, 2016
Feb 5, 2016
Jun 15, 2017
May 24, 2018
Sep 7, 2018
Sep 26, 2016
Dec 19, 2017
Feb 10, 2016
Sep 7, 2018
May 1, 2014
Feb 4, 2016
Jun 15, 2017
Apr 20, 2017
Jun 15, 2017

Repository files navigation

dart_to_js_script_rewriter

Pub Build Status codecov.io

A pub transformer that rewrites Dart script tags to JavaScript script tags, eliminating 404s and speeding up initial loads. Useful when building for deployment.

Why? Load your app quicker!

A traditional Dart application is deployed with HTML that looks something like this:

<script async type="application/dart" src="test.dart"></script>
<script async src="packages/browser/dart.js"></script>

This is a performance problem for initial startup, because:

  • Some browsers will attempt to download test.dart, but that file is not deployed. This causes unnecessary server strain and noisy 404s.
  • The browser needs to run dart.js to replace a script tag in the DOM, so that the actual JavaScript version of the app can be downloaded. This is an unnecessary delay, since today no production browser includes Dart VM and thus only the JavaScript version is required.

With this transformer, you can address the above issues, speed up the load time of your apps, and make happier users.

Configuring

Add the transformer to your pubspec.yaml:

transformers:
- dart_to_js_script_rewriter

(Assuming you already added this package to your pubspec.yaml file.)

How it works

When run in "release" mode, this transformer does two things:

  • Removes script tags that point to browser/dart.js.
  • Rewrites a Dart script tag to a JavaScript script tag.

For example, this code:

<script async type="application/dart" src="test.dart"></script>
<script async src="packages/browser/dart.js"></script>

is turned into this code:

<script async src="test.dart.js"></script>

Pub, modes, and this transformer

This transformer only runs when pub is running in release mode.

This transformer only makes sense when you want to build your app for a production deployment. You probably do not want to run this transformer during the normal develop/reload cycles.

Pub can run in different modes, which have different semantics. The debug mode, for example, can disable minification. The release mode can turn on optimizations.

By default, pub serve runs in debug mode. By default, pub build runs in release mode.

See the pub docs for more on modes.

Reporting issues

Please use the issue tracker.

Thanks to Seth Ladd, [email protected], for creating the original version of this library.

About

A pub transformer that Rewrites Dart script tags to JavaScript script tags, eliminating 404s and speeding up initial loads. Use when building for deployment.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published