├── .gitignore
├── .travis.yml
├── CHANGELOG.md
├── CODEOWNERS
├── COPYRIGHT_TRANSFER
├── Dockerfile
├── LICENSE
├── README.md
├── analysis_options.yaml
├── docs.yml
├── example
├── index.html
├── test.css
└── test.dart
├── lib
└── dart_to_js_script_rewriter.dart
├── pubspec.yaml
├── test
├── expected.html
├── integration_test.dart
├── test_data
│ └── test_file.html
├── transformer_mocks.dart
└── unit_test.dart
└── tool
└── dev.dart
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .dart_tool/
3 | .pub/
4 | .settings/
5 | build
6 | coverage/
7 | packages
8 | pubspec.lock
9 | .packages
10 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: dart
2 | dart:
3 | - 1.24.3
4 | script:
5 | - pub run dart_dev format --check
6 | - pub run dart_dev analyze
7 | - pub run dart_dev test
8 | - pub run dart_dev coverage --no-html
9 | - bash <(curl -s https://codecov.io/bash) -f coverage/coverage.lcov
10 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## 1.0.2
2 |
3 | * Updated dependencies on `html` and `dartdoc`.
4 |
5 | ## 0.1.0+4
6 |
7 | * [fix] only rewrite dart.js from browser package
8 |
9 | ## 0.1.0+3
10 |
11 | * Update dependencies
12 |
13 | ## 0.1.0+2
14 |
15 | * Removed special handling of the csp mode - dart2js no longer uses a special
16 | output file name
17 |
18 | ## 0.1.0+1
19 |
20 | * Added tests
21 |
22 | ## 0.0.2
23 |
24 | * CSP support (thanks to claudiodangelis)
25 |
26 | ## 0.0.1+3
27 |
28 | * Bump dependency versions (thanks to kaendfinger)
29 |
30 | ## 0.0.1+2
31 |
32 | * Add a "why?" section to the README.
33 |
34 | ## 0.0.1+1
35 |
36 | * Tweak readme.
37 |
38 | ## 0.0.1
39 |
40 | * Initial version.
41 |
--------------------------------------------------------------------------------
/CODEOWNERS:
--------------------------------------------------------------------------------
1 | * @Workiva/app-frameworks
2 |
3 |
--------------------------------------------------------------------------------
/COPYRIGHT_TRANSFER:
--------------------------------------------------------------------------------
1 | I, Seth Ladd, hereby assign copyright of dart_to_js_script_rewriter to Workiva Inc.
2 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM google/dart:1.24.3
2 |
3 | WORKDIR /build/
4 | ADD pubspec.yaml /build
5 | RUN pub get
6 | ARG BUILD_ARTIFACTS_AUDIT=/build/pubspec.lock
7 | FROM scratch
8 |
9 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014 Seth Ladd. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of Google Inc. nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # dart_to_js_script_rewriter
2 |
3 |
4 |
5 |
6 |
7 |
8 | A pub transformer that rewrites Dart script tags to
9 | JavaScript script tags, eliminating
10 | 404s and speeding up initial loads.
11 | Useful when building for deployment.
12 |
13 | ## Why? Load your app quicker!
14 |
15 | A traditional Dart application is deployed with HTML that looks something
16 | like this:
17 |
18 |
19 |
20 |
21 | This is a performance problem for initial startup, because:
22 |
23 | * Some browsers will attempt to download test.dart, but that file is not
24 | deployed. This causes unnecessary server strain and noisy 404s.
25 | * The browser needs to run dart.js to replace a script tag in the DOM,
26 | so that the actual JavaScript version of the app can be downloaded. This is
27 | an unnecessary delay, since today no production browser includes Dart VM
28 | and thus only the JavaScript version is required.
29 |
30 | With this transformer, you can address the above issues, speed up the load
31 | time of your apps, and make happier users.
32 |
33 | ## Configuring
34 |
35 | Add the transformer to your pubspec.yaml:
36 |
37 | transformers:
38 | - dart_to_js_script_rewriter
39 |
40 | (Assuming you already added this package to your pubspec.yaml file.)
41 |
42 | ## How it works
43 |
44 | **When run in "release" mode**, this transformer does two things:
45 |
46 | * Removes script tags that point to `browser/dart.js`.
47 | * Rewrites a Dart script tag to a JavaScript script tag.
48 |
49 | For example, this code:
50 |
51 |
52 |
53 |
54 | is turned into this code:
55 |
56 |
57 |
58 | ## Pub, modes, and this transformer
59 |
60 | **This transformer only runs when pub is running in release mode.**
61 |
62 | This transformer only makes sense when you want to build your app for a
63 | production deployment. You probably do not want to run this transformer
64 | during the normal develop/reload cycles.
65 |
66 | Pub can run in different _modes_, which have different semantics. The
67 | _debug mode_, for example, can disable minification. The _release mode_
68 | can turn on optimizations.
69 |
70 | By default, `pub serve` runs in _debug_ mode. By default, `pub build`
71 | runs in _release_ mode.
72 |
73 | See the [pub docs][pubdocs] for more on modes.
74 |
75 | ## Reporting issues
76 |
77 | Please use the [issue tracker][issues].
78 |
79 | [issues]: https://github.com/Workiva/dart_to_js_script_rewriter/issues
80 | [pubdocs]: https://www.dartlang.org/tools/pub/
81 |
82 | Thanks to Seth Ladd, , for creating the original version of this [library](https://github.com/sethladd/dart_to_js_script_rewriter).
83 |
--------------------------------------------------------------------------------
/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | analyzer:
2 | strong-mode: true
3 |
4 | linter:
5 | rules:
6 | - cancel_subscriptions
7 | - close_sinks
--------------------------------------------------------------------------------
/docs.yml:
--------------------------------------------------------------------------------
1 | title: dart_to_js_script_rewriter
2 | base: github:Workiva/dart_to_js_script_rewriter/
3 | src: README.md
4 |
--------------------------------------------------------------------------------
/example/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Test
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |