node_preamble 1.4.10

  • Readme
  • Changelog
  • Example
  • Installing
  • 99

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() {

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

1.4.10 #

Oops, fix Electron capabilities to be correct. Sorry about this!

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.7 when minified file is used.

1.4.7 #

Thanks! @lexaknyazev

  • Move url module import to Node.js-only block.
  • Fix for when we try to load url on Node.js but are also using Webpack.

1.4.6 #

  • Make location.href compatible with Node versions earlier than 10.12.0 again.

1.4.5 #

  • Improve location.href so that Dart's Uri.current works for more paths.

    • Make location.href a getter so Dart's Uri.current changes along with the process's working directory.
  • 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.base up 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.js and by calling getPreamble(minified: true).

1.2.0 #

  • Prevent encapsulation, global.self = global (old) vs. var self = Object.create(global) (new).

1.1.0 #

  • Set global.location so that Uri.base() works properly on Windows in most cases.

  • Define global.exports so that it's visible to the compiled JS.


import "package:node_preamble/preamble.dart" as preamble;

main() {

Use this package as a library

1. Depend on it

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

  node_preamble: ^1.4.10

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:node_preamble/preamble.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jun 4, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.2
  • pana: 0.13.8-dev

Health suggestions

Fix lib/preamble.dart. (-1 points)

Analysis of lib/preamble.dart reported 2 hints:

line 123 col 34: Use = to separate a named parameter from its default value.

line 123 col 73: Use = to separate a named parameter from its default value.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.24.0 <3.0.0
Dev dependencies
http ^0.11.0