dart_to_js_script_rewriter 0.1.0+3

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • --

dart_to_js_script_rewriter #

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 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.

CHANGELOG #

0.1.0+3 #

  • Update dependencies

0.1.0+2 #

  • Removed special handling of the csp mode - dart2js no longer uses a special output file name

0.1.0+1 #

  • Added tests

0.0.2 #

  • CSP support (thanks to claudiodangelis)

0.0.1+3 #

  • Bump dependency versions (thanks to kaendfinger)

0.0.1+2 #

  • Add a "why?" section to the README.

0.0.1+1 #

  • Tweak readme.

0.0.1 #

  • Initial version.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dart_to_js_script_rewriter: ^0.1.0+3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dart_to_js_script_rewriter/dart_to_js_script_rewriter.dart';
  
Version Uploaded Documentation Archive
1.0.3 Jun 15, 2017 Go to the documentation of dart_to_js_script_rewriter 1.0.3 Download dart_to_js_script_rewriter 1.0.3 archive
1.0.2 Sep 26, 2016 Go to the documentation of dart_to_js_script_rewriter 1.0.2 Download dart_to_js_script_rewriter 1.0.2 archive
1.0.1 Feb 25, 2016 Go to the documentation of dart_to_js_script_rewriter 1.0.1 Download dart_to_js_script_rewriter 1.0.1 archive
0.1.0+4 Sep 26, 2015 Go to the documentation of dart_to_js_script_rewriter 0.1.0+4 Download dart_to_js_script_rewriter 0.1.0+4 archive
0.1.0+3 Aug 16, 2015 Go to the documentation of dart_to_js_script_rewriter 0.1.0+3 Download dart_to_js_script_rewriter 0.1.0+3 archive
0.1.0+1 Feb 7, 2015 Go to the documentation of dart_to_js_script_rewriter 0.1.0+1 Download dart_to_js_script_rewriter 0.1.0+1 archive
0.1.0 Feb 7, 2015 Go to the documentation of dart_to_js_script_rewriter 0.1.0 Download dart_to_js_script_rewriter 0.1.0 archive
0.0.2 Sep 11, 2014 Go to the documentation of dart_to_js_script_rewriter 0.0.2 Download dart_to_js_script_rewriter 0.0.2 archive
0.0.1+3 Sep 11, 2014 Go to the documentation of dart_to_js_script_rewriter 0.0.1+3 Download dart_to_js_script_rewriter 0.0.1+3 archive
0.0.1+2 May 1, 2014 Go to the documentation of dart_to_js_script_rewriter 0.0.1+2 Download dart_to_js_script_rewriter 0.0.1+2 archive

All 12 versions...

Awaiting analysis to complete.