airdrop-cli is a package delivery tool for ES modules from npm packages. Use it to deliver packages from npm to the browser with no external connection needed at runtime.
- Downloads and extracts packages from npm, including dependencies, into a flat file structure.
- Optionally bundles packages, and dependencies, into a single ES module.
- Generates a import-map compatible with the WICG import-maps proposal (and shims).
- Provides a method to archive and merge downloaded packages and import-maps between systems.
$ npm install @swimlane/airdrop-cli -g
npx @swimlane/airdrop-cliin place of
airdropin the examples below.
airdrop add <package> [<package>] [--force] [--bundle] [--optimize] [--clean]
addcommand is optional; the default
<package>: npm package(s) (with optional version or tag) to add
--force: force add package(s) that have already been added
--bundle: bundle the added package(s)
--optimize: minify the generated bundle(s)
--clean: clean output directory before adding new packages
--no-color: disable CLI colors
The cli supports multiple packages and semantic version ranges. For example
airdrop add lit-element email@example.com install the latest version of
lit-elementand an exact version of
Packages added using
airdrop <package> are downloaded into a
<package_path>/<name>@<version>/ directory. The same happens for each dependency of
<package>. An import-map in the
<package_path> directory is added or updated.
For example, running
airdrop firstname.lastname@example.org results in a
<package_path> directory structure of:
<package_path> ├── email@example.com/ ├── firstname.lastname@example.org/ └── importmap.json
and an import-map of:
<package_path>directory is configurable via the
airdrop.config.js, the default is
./-/. In the generated import-maps, the package address is configurable via the
package_rootproperty, the default is
/-/. This value must start with
./, or be an absolute URL.
--bundle flag adds and bundles each
<package> into a esm bundle (and with inlined dependencies) at
<package_path>/<name>@<version>.bundle.js. The import-map is updated to resolve
<name>@<version> to the bundle.
For example, running
airdrop email@example.com --bundle results in a root directory structure of:
<package_path> ├── <d3 deps> ├── firstname.lastname@example.org/ ├── email@example.com └── importmap.json
and an import-map of:
airdropadds an import of the form
<name>@<major-version>that resolves to the latest local version of the package.
Adding packages requires a connection to the npm registry. Once added an external connection is no longer required. The
<package_path> directory can be deployed with other static assets or just manually copied between systems.
The following commands help move content from one system to another:
airdrop pack [<filename>]- Creates a tarball from the
<filename>is optional and defaults to using a timestamp.
airdrop merge <filename>- Unpacks a tarball to the
<package_path>directory, merging the packed import-map with the existing import-map.
airdrop init- Adds an
airdrop.config.jsto the current directory and an empty import-map.
airdrop version- Outputs the version number.
airdrop config- Displays current configuration.
airdrop clean- Cleans the output directory.
airdrop resolve <package>- Prints the resolved url for package(s).
In browser usage
The added ES modules can be loaded in the browser using a absolute path and full version.
airdrop resolve <package>to find the resolved path.
Or with the dynamic
While most modern browsers include support for ES modules, bare package specifiers are explicitly forbidden. In order to import bare package specifiers like
import "lit-html" we need import-maps.
Note: import-maps are still an experimental specification. Use es-module-shims to polyfill most of the newer modules specifications. SystemJS also supports import-maps. However,
System.registermodules or AMD modules via extras.
Bundles can also be imported using fixed versions or bare imports when combined with the import-map.
- lit-element project (with shims and import-map): https://gist.github.com/Hypercubed/6a2c7e5c21355bc109f0c06e6a5a62c8
- d3 project (bundled, no shims or import-map necessary): https://gist.github.com/Hypercubed/e6f198ff61f5d2d9ec3a540a0ac3b9ca
airdrop is a Swimlane open-source project; we believe in giving back to the open-source community by sharing some of the projects we build for our application. Swimlane is an automated cyber security operations and incident response platform that enables cyber security teams to leverage threat intelligence, speed up incident response and automate security operations.