These tasks compile the package to JavaScript, build npm packages, and
upload them to the npm registry. They're enabled by calling
pkg.addNpmTasks()
.
Note that all JS compilation requires that a package.json
file exist at the
root of your package, or that you set the pkg.npmPackageJson
field.
Either way, you must at least include the "name"
field.
When compiled to JS, the package has access to the version
and dartVersion
environment declarations, which provide the package's version and the version of
Dart that it was compiled with, respectively. They can be accessed with
String.fromEnvironment()
. It also sets the node
environment declaration
to true
, which can be accessed through bool.fromEnvironment()
.
The package is built with the --server-mode
option, which allows conditional
imports to be used to load different libraries when compiling for JavaScript
than you do when running on the VM:
// lib/src/io.dart
// Export a Dart-VM-compatible IO library by default, and a Node.js-compatible
// one when compiling to JavaScript.
export 'io/vm.dart'
if (dart.library.js) 'io/node.dart';
You can export JavaScript functions from your package so it can be loaded as a
library in addition to having its executables invoked. See
pkg.jsModuleMainLibrary
for more details.
Uses configuration: pkg.executables
, pkg.version
, pkg.jsFlags
,
pkg.jsDevFlags
, pkg.jsRequires
, pkg.jsModuleMainLibrary
,
pkg.jsForceStrictMode
, pkg.npmPackageJson
Output: build/$name.dart.js
Compiles all this package's executables to a single JavaScript file, in development mode. By default, development mode has all optimizations disabled.
Uses configuration: pkg.executables
, pkg.version
, pkg.jsFlags
,
pkg.jsReleaseFlags
, pkg.jsRequires
, pkg.jsModuleMainLibrary
,
pkg.jsForceStrictMode
, pkg.npmPackageJson
Output: build/$name.dart.js
Compiles all this package's executables to a single JavaScript file, in release
mode. By default, release mode uses dart2js's -O4
flag, with minification
disabled.
Depends on: pkg-js-dev
Uses configuration: pkg.executables
, pkg.version
, pkg.npmPackageJson
, pkg.jsModuleMainLibrary
, pkg.npmReadme
, pkg.npmDistTag
, pkg.npmAdditionalFiles
Output: build/npm/*
Creates an npm-compatible package directory containing this package's compiled
dev-mode JavaScript, shims to invoke each executable's main()
method, and its
package.json
.
It will also include a README if pkg.npmReadme
isn't null, and a LICENSE
if one exists at the top level of the package.
Executables from this package can be invoked using testing APIs such as
pkg.start()
, pkg.executableRunner()
, and pkg.executableArgs()
.
Depends on: pkg-js-release
Uses configuration: pkg.executables
, pkg.version
, pkg.npmPackageJson
, pkg.jsModuleMainLibrary
, pkg.npmReadme
, pkg.npmAdditionalFiles
Output: build/npm/*
Creates an npm-compatible package directory containing this package's compiled
release-mode JavaScript, shims to invoke each executable's main()
method, and
its package.json
.
It will also include a README if pkg.npmReadme
isn't null, and a LICENSE
if one exists at the top level of the package.
Depends on: pkg-npm-release
Uses configuration: pkg.npmToken
Publishes the package to the npm registry.