commit | d278def486af63c43686408f190c6faf82fd0439 | [log] [tgz] |
---|---|---|
author | mnito <mpnitowski@gmail.com> | Sat Apr 09 17:28:40 2022 -0400 |
committer | mnito <mpnitowski@gmail.com> | Sat Apr 09 17:48:38 2022 -0400 |
tree | ceec99ce8beeca32cbfbe39c1c16a99dd383f7aa | |
parent | 3c83ba0887fb64424d3336338da393e4f0eecbf4 [diff] |
Enable including libraries with a preamble via the HTML script tag Mutating the self variable with Object.create on the window global makes objects included on js.context within Dart unavailable in the browser environment. Fix this issue by only preventing encapsulation via Object.create when necessary and not in the browser. Additionally, browsers tend to not have CommonJS globals available. To prevent ReferenceErrors when running in the browser, check if these globals are available before setting them on self.
A simple package for a better dart2js preamble for running on node.js. This package exists for ease of use if incorporating into your build system.
This preamble is suggested for use over d8.js, and provides many improvements and bug fixes, as it uses node.js's timer functions and event loop over the custom one implemented in d8.js.
The JavaScript file can be found at lib/preamble.js.
You can also get the preamble via Dart, like in the following example.
import "package:node_preamble/preamble.dart" as preamble; main() { print(preamble.getPreamble()); }
Credit goes to the Dart team for creating Dart, dart2js, and the original preamble which this is derived from.
The only file that we directly modify is preamble.js
. After that, to reflect your changes in both preamble.dart
and preamble.min.js
, run npm install && npm run minify
node_preamble
tries to support the following platforms. Before a pub
release, the following environments should be manually tested with a sample dart2js
output:
node
create-react-app
)