handroll
Expertly rolled JavaScript
JavaScript API and CLI for for bundling opinionated JavaScript with
Rollup. Provides a similar interface to
Rollup with many options and plugins automatically configured based on format
and package.json
.
Features
- Automatic external module detection
- Automatic node module resolution with improved resolution strategy
- Automatic transforms based on filetype with built-in support for many languages
- Automatic destination and format detection based on
package.json
:main
generates CommonJS modulemodule
generates ES module bundlebin
generates executable
- Higher-level formats
cli
bundles JS into an executableweb
bundles JS for the browser
- Built-in minification support
- Built-in legacy module support
- Built-in CommonJS support
- Built-in statistics and details view
- Improved error handling and logging
- Sensible defaults
Install
$ npm install handroll -g
CLI
handroll Usage: handroll <entry> [options] Options: --commonjs Enable CommonJS support --output, -o Destination to write output --format, -f Format to output --formats Comma separated list of formats to output --es ES module format --cjs CommonJS module format --cli Executable format --web Web format --browser Bundle
JavaScript API
Handroll's JavaScript API provides an interface similar to Rollup, with the
bundle
step being optional (and only useful if you want to cache the
intermediate bundle). In most cases you'll want to use .write
or .generate
directly.
handroll.bundle (options) -> Promise
Create a new Bundle
and cache result of bundle.rollup
.
handroll.write (options) -> Promise
Create new Bundle
and immediately export in appropriate format(s).
bundle.write (options) -> Promise
Write bundle in appropriate format(s).
bundle.generate (options) -> Promise
Generate output in appropriate format(s).
bundle.rollup (options) -> Promise
Automatically infer compilers, plugins, formats and other relevant options and Rollup bundle.
options
All Handroll operations can be passed the similiar options.
const bundle = await handroll
Examples
// Create new bundleconst bundle = await handroll // Write ES module (for use by bundlers)await bundle // Write CommonJS module (for use by Node.js)await bundle // Write ES module and CommonJS moduleawait bundle // If you specify 'main' and 'module' in your package.json, both ES module and// CommonJS formatted bundles will be generatedawait bundle // Write self-executing bundle for web using browser-friendly modules, ensuring no// dependencies are excludedawait bundle // Write executable with shebang using new entry moduleawait handroll // Share options across multiple destinationsconst bundle = entry: 'src/index.js' external: falseawait Promiseall bundle bundle
package.json
Example "name": "mylib" "main": "lib/mylib.js" // CommonJS output "module": "lib/mylib.mjs" // ES module output "jsnext:main": "lib/mylib.mjs" // For compatibility with outdated bundlers // To ensure your generated files are packaged correctly: "files": "lib/" "src/" "scripts": "prepublishOnly": "handroll src/index.js --formats cjs,es"