dart_to_js_script_rewriter 1.0.3

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 99

dart_to_js_script_rewriter

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

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

1.0.2

  • Updated dependencies on html and dartdoc.

0.1.0+4

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

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.

1. Depend on it

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


dependencies:
  dart_to_js_script_rewriter: "^1.0.3"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or packages 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...

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Jan 17, 2018
  • Dart: 2.0.0-dev.15.0
  • pana: 0.9.1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
99 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
99

Platforms

Detected platforms: Flutter, server

Multiple platform identified in libraries.

Suggestions

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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.12.0 <2.0.0
barback ^0.15.2+7 0.15.2+14
html >=0.12.2+1 <0.14.0 0.13.2+2
Transitive dependencies
args 1.2.0
async 2.0.3
charcode 1.1.1
collection 1.14.5
csslib 0.14.1
logging 0.11.3+1
path 1.5.1
pool 1.3.4
source_span 1.4.0
stack_trace 1.9.1
utf 0.9.0+3
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