pub repository
mirror.p-hatan.irnode_preamble
2.0.2Better node.js preamble for dart2js, use it in your build system.
Readme
node_preamble.dart
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.
Contributing
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
Testing
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- Webpack (easy way is with
create-react-app) - Electron Fiddle (w/ and w/o node integration)
Changelog
2.0.2
- Don't crash when running in browser environments.
2.0.1
- Define properties for
global.locationandglobal.documentrather than setting them. This avoidsTypeErrors on Electron.
2.0.0
- Null safety release.
1.4.13
- Fixes detection on Electron with
nodeIntegrationdisabled
1.4.10-1.4.12
Hotfix again for Electron support, quite embarassing at this point. Verified using the awesome Electron Fiddle tool.
1.4.9
- Change behavior of Node.js detection that now takes into account:
- Web workers in browser
- Electron
1.4.8
- Fixed previous build
1.4.7when minified file is used.
1.4.7
Thanks! @lexaknyazev
- Move
urlmodule import to Node.js-only block. - Fix for when we try to load
urlon Node.js but are also using Webpack.
1.4.6
- Make
location.hrefcompatible with Node versions earlier than 10.12.0 again.
1.4.5
-
Improve
location.hrefso that Dart'sUri.currentworks for more paths.- Make
location.hrefa getter so Dart'sUri.currentchanges along with the process's working directory.
- Make
-
Fixes for Angular 6+ applications using compiled Dart package w/ preamble:
- Checks for global if it's not polyfilled, then try for window.
- Don't assume that since we have CommonJS we have process, __dirname, __filename.
1.4.4
- Explicitly support Dart 2 stable releases.
1.4.3
- Add Node detector for Browserify/Webpack-type environments. (thanks to @lexaknyazev for reporting!)
- Add examples for pub (thanks @bcko!)
1.4.2
- Keep
Uri.baseup to date when the current working directory changes. - Add .dart_tool to gitignore.
1.4.1
- Make sure to replace all backslashes for cwd on Windows, not just the first.
1.4.0
- Add __dirname and __filename to exposed globals. Adds ability of exposing more
globals in the preamble by calling
getPreamble(additionalGlobals: ["__dirname", ...]).
1.3.0
- Add minified versions of the preamble accessible as
lib/preamble.min.jsand by callinggetPreamble(minified: true).
1.2.0
- Prevent encapsulation,
global.self = global(old) vs.var self = Object.create(global)(new).
1.1.0
-
Set
global.locationso thatUri.base()works properly on Windows in most cases. -
Define
global.exportsso that it's visible to the compiled JS.
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add node_preamblepubspec.yaml
name: node_preamble
author: Michael Bullington <mikebullingtn@gmail.com>
homepage: https://github.com/mbullington/node_preamble.dart
version: 2.0.2
description: Better node.js preamble for dart2js, use it in your build system.
environment:
sdk: '>=2.12.0-0 <3.0.0'
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 1.0.0 | 2015-08-24T03:09:46.852Z | Download | 1d7c0be1df059b95e11b2c0571cc02e3753a7a114f61ca240d629072d7777b74 |
| 1.1.0 | 2016-12-02T23:19:32.674Z | Download | 078cdd99bcd7f020810c2f5e0477ce9438f0ba4e0d80f4af11591244b38e76ef |
| 1.2.0 | 2016-12-03T00:09:08.131Z | Download | 970006d1e5dc58358eeee768c44adacbcaae3c5fb4a8a2be2ce4d7ee4584a0a2 |
| 1.3.0 | 2017-03-12T00:04:23.667Z | Download | 5873b9fef32b99c815be4e567172818dd5bc50970fd0b8610fa644e34913f332 |
| 1.4.0 | 2017-06-30T16:15:07.531732Z | Download | 480628b8063ea75023203641462c2a24ffa7ecf20960877f5df7740d36ce8698 |
| 1.4.1 | 2018-04-25T22:58:40.162326Z | Download | 427980a413a23c85361eb1acbf968973bf145a7633b5ce55c18edbe6605fc89f |
| 1.4.2 | 2018-05-25T23:36:58.798725Z | Download | 3a3be084f2758ebc578bf0547d96cdb0fbda14024ab7ebf40535a60bf7cf0aeb |
| 1.4.3 | 2018-07-01T06:29:13.490888Z | Download | 4ca69f92864e1afdf51785d32fd7edec524f8d11690a140c404f2eeef4c4b6c0 |
| 1.4.4 | 2018-07-24T17:32:40.272250Z | Download | ba9c0e22dd12237f404a7c965951d2c69ae78e529ae9a4fa6aa2a2417163f52f |
| 1.4.5 | 2019-07-22T07:03:33.036072Z | Download | c10e8a5aa518d87e16161544c855ada8963ec0f8f90397e8ed026db01df99727 |
| 1.4.6 | 2019-07-27T23:37:08.146920Z | Download | 4fecbfadaffde1bf075aeb3d615482e19a58f7b98c94586405e1a368008f979c |
| 1.4.7 | 2019-09-04T01:49:39.603846Z | Download | 767ef8efc9ae106ff2c9f5d07f3bc56ab976a22c43524136c051ec5290aa9f24 |
| 1.4.8 | 2019-09-10T21:05:02.061256Z | Download | 2c4565b1d416fc68935b1bb5d5e8fbed843d828ef26244cd14b2ea267b745064 |
| 1.4.9 | 2020-05-23T22:37:36.388205Z | Download | 1d0bad4d4fa4e385cecb7c9c8c7fa6e6f7b0ed15029216c9707374eef314f1f9 |
| 1.4.10 | 2020-06-03T04:15:49.662522Z | Download | 2c001095d140de1f49ec0a75a3861557f56e39eeea7674ffbc4f5c2b9a803804 |
| 1.4.11 | 2020-06-10T05:48:15.834539Z | Download | da2cfccc846e5bc61c343faa6bc3c452065ff876cb2cb253f375a0c643ae13d2 |
| 1.4.12 | 2020-06-10T05:50:31.407053Z | Download | 19fbcd082b2ca6ca7874571e11120d025134995103e0ff3905666779048ad893 |
| 1.4.13 | 2021-01-25T03:30:40.194877Z | Download | 847d2400938dd2594b4617244c4a9d477e939d0e134746ae88d9497e0ecb0a71 |
| 2.0.0 | 2021-03-03T18:32:55.343147Z | Download | c133f761a6a790d0b000efa4f74eae9700bb6e9e9f5e996f0e8d6fe92703ced6 |
| 2.0.1 | 2021-06-16T04:02:03.443896Z | Download | 8ebdbaa3b96d5285d068f80772390d27c21e1fa10fb2df6627b1b9415043608d |
| 2.0.2 | 2023-03-01T06:25:31.131415Z | Download | 6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db |
Dependencies
No direct dependencies declared.