dart_to_js_script_rewriter 1.0.3

  • README.md
  • Installing
  • Versions
  • 90


<a href="https://pub.dartlang.org/packages/dart_to_js_script_rewriter"><img src="https://img.shields.io/pub/v/dart_to_js_script_rewriter.svg" alt="Pub" /></a> <a href="https://travis-ci.org/Workiva/dart_to_js_script_rewriter"><img src="https://travis-ci.org/Workiva/dart_to_js_script_rewriter.svg?branch=travis-ci" alt="Build Status" /></a> <a href="http://codecov.io/github/Workiva/dart_to_js_script_rewriter?branch=master"><img src="http://codecov.io/github/Workiva/dart_to_js_script_rewriter/coverage.svg?branch=master" alt="codecov.io" /></a>

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.


Add the transformer to your pubspec.yaml:

- 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, sethladd@gmail.com, for creating the original version of this library.


  • Updated dependencies on html and dartdoc.


  • [fix] only rewrite dart.js from browser package


  • Update dependencies


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


  • Added tests


  • CSP support (thanks to claudiodangelis)


  • Bump dependency versions (thanks to kaendfinger)


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


  • Tweak readme.


  • Initial version.

Use this package as a library

1. Depend on it

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

  dart_to_js_script_rewriter: "^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...


We analyzed this package on Jul 13, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3


Describes how popular the package is relative to other packages. [more]
85 / 100
Code health derived from static analysis. [more]
98 / 100
Reflects how tidy and up-to-date the package is. [more]
92 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: web

Whitelisted platform override.


  • Package is getting outdated.

    The package was released 56 weeks ago.

  • Maintain an example.

    None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use dart_to_js_script_rewriter.dart.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 1 hint.

    Strong-mode analysis of lib/dart_to_js_script_rewriter.dart gave the following hint:

    line: 5 col: 1
    'barback' is deprecated and shouldn't be used.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.12.0 <2.0.0
barback ^0.15.2+7 0.15.2+16
html >=0.12.2+1 <0.14.0 0.13.3+1
Transitive dependencies
args 1.4.3
async 2.0.7
charcode 1.1.2
collection 1.14.10
csslib 0.14.4
logging 0.11.3+1
path 1.6.1
pool 1.3.5
source_span 1.4.0
stack_trace 1.9.2
utf 0.9.0+4
Dev dependencies
browser ^0.10.0+2
coverage ^0.7.2
dart_dev ^1.0.6
dart_style >=0.1.8 <0.3.0
dartdoc >=0.4.0 <0.10.0
grinder ^0.8.0+1
mockito any
test ^0.12.6+2