A pub transformer that rewrites Dart script tags to JavaScript script tags, eliminating 404s and speeding up initial loads. Useful when building for deployment.
A traditional Dart application is deployed with HTML that looks something like this:
<script async type="application/dart" src="https://github.com/Workiva/dart_to_js_script_rewriter/raw/master/test.dart"></script>
<script async src="https://github.com/Workiva/dart_to_js_script_rewriter/raw/master/packages/browser/dart.js"></script>
This is a performance problem for initial startup, because:
With this transformer, you can address the above issues, speed up the load time of your apps, and make happier users.
Add the transformer to your pubspec.yaml:
transformers:
- dart_to_js_script_rewriter
(Assuming you already added this package to your pubspec.yaml file.)
When run in "release" mode, this transformer does two things:
browser/dart.js
.For example, this code:
<script async type="application/dart" src="https://github.com/Workiva/dart_to_js_script_rewriter/raw/master/test.dart"></script>
<script async src="https://github.com/Workiva/dart_to_js_script_rewriter/raw/master/packages/browser/dart.js"></script>
is turned into this code:
<script async src="https://github.com/Workiva/dart_to_js_script_rewriter/raw/master/test.dart.js"></script>
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.
Please use the issue tracker.
Thanks to Seth Ladd, sethladd@gmail.com, for creating the original version of this library.