rollup-babel-lib-bundler

Utility to bundle JavaScript libraries with Rollup

Please use 'microbundle' or 'tsdx' instead
Last updated 3 years ago by stoney .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install rollup-babel-lib-bundler 
SYNC missed versions from official npm registry.

rollup-babel-lib-bundler

Utility to bundle JavaScript libraries with Rollup. An opiniated configuration preset for Rollup to use for bundling libraries

Build Status Dependency Status devDependency Status Coverage Status

As a library author, I always wanted to have a utility where I put in a file and I get a library for all the formats I want to distribute. (Ideally, it should pick up my Babel config and the library name from the package.json.)

Originally, this started as a build script in one of open source projects, but then I needed it in other projects as well. That's when it became a NPM module.

I really like Rollup's idea of not scoping each module individually which is closer to my perception of what the library what would look like if I were to write the library by hand without modules.

Installation

$ npm install rollup-babel-lib-bundler

Usage

Rollup requires a rollup-compatible Babel config. Simply change the es2015 preset to es2015-rollup or es2015-loose to es2015-loose-rollup.

usage

Command-line

rollup-babel-lib-bundler ./myFancyLibrary.js

Call rollup-babel-lib-bundler without any arguments to see all options.

The command-line app also supports passing in options through the package.json. Simply create a property called rollupBabelLibBundler. An example configuration would look like this:

"rollupBabelLibBundler": {
  "moduleName": "myFancyLibrary",
  "dest": "dist",
  "babel": {
    "presets": ["es2015-rollup", "stage-1"]
  }
}

It also allows passing in Babel options passed in here. This will take precedence over the .babelrc file. The options are passed into the rollup-babel-plugin where the options are slightly different from the official Babel configuration. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more details.

Command-line options > Package configuration options
Package babel configuration > .babelrc

If using the command-line utility, no imports will be included by default. If any package name is included in bundleDependencies it will be part of the resulting bundle. For the equivalent in the JavaScript API, see options.externals.

JavaScript API

The API is very similar to a Rollup config file. In fact, additional options will be passed into Rollup or plugins rollup-babel-lib-bundler uses.

var rollupBabelLibBundler = require('rollup-babel-lib-bundler');

rollupBabelLibBundler({
  name: 'myfancylibrary',
  moduleName: 'myFancyLibrary',
  dest: 'dist',
  entry: './myFancyLibrary.js',
  format: ['cjs', 'umd', 'es6'],
  postfix: { cjs: '.common' },
});

options.name

Type: String
Default: mylibrary

The name of the library. Will be used for the generated filenames.

options.moduleName

Type: String
Default myLibrary

This is needed for the UMD build. This is the property the library will bind itself to the global object. If omitted, it will automatically use options.name as camel case.

options.dest

Type: String
Default dist

The directory where the files will be generated to.

options.entry

Type: String
Default index.js

The path to the library itself.

options.format

Type: Array
Default ['umd', 'es6', 'cjs']

Can be umd, es6, cjs, iife or a combination of these.

options.postfix
Type: Object
Default { cjs: '', es6: '.es2015', umd: '.umd', iife: '.iife' }

Allows to define custom postfixes for each module type. .js will automatically be prepended.

options.babel

Type: String or Object

Allow to overwrite the babel configuration. By default its value is inherit and it will take the closest .babelrc file.

options.externals

Type Array<String>
Default []

Any dependencies that are being used will be inserted into the bundle by default. If any packages are defined in this array, they won't be included in the bundle.

Return value

Type: Promise

This returns a promise with an array of objects which have the following format:

{
  name: String, // The module name
  format: String, // The module format (es6, umd, cjs)
  endTime: Number, // The time where this module finished generating
  startTime: Number, // The time before the generating process started
}

License

MIT

Current Tags

  • 3.1.0                                ...           latest (3 years ago)

34 Versions

  • 3.1.0 [deprecated]           ...           3 years ago
  • 3.0.2 [deprecated]           ...           3 years ago
  • 3.0.1 [deprecated]           ...           3 years ago
  • 3.0.0 [deprecated]           ...           3 years ago
  • 3.0.0-alpha1                                ...           3 years ago
  • 2.6.2 [deprecated]           ...           3 years ago
  • 2.6.1 [deprecated]           ...           3 years ago
  • 2.6.0 [deprecated]           ...           3 years ago
  • 2.5.5 [deprecated]           ...           4 years ago
  • 2.5.4 [deprecated]           ...           4 years ago
  • 2.5.3 [deprecated]           ...           4 years ago
  • 2.5.2 [deprecated]           ...           4 years ago
  • 2.5.1 [deprecated]           ...           4 years ago
  • 2.5.0 [deprecated]           ...           4 years ago
  • 2.4.0 [deprecated]           ...           4 years ago
  • 2.3.6 [deprecated]           ...           4 years ago
  • 2.3.5 [deprecated]           ...           4 years ago
  • 2.3.4 [deprecated]           ...           4 years ago
  • 2.3.3 [deprecated]           ...           4 years ago
  • 2.3.2 [deprecated]           ...           4 years ago
  • 2.3.1 [deprecated]           ...           4 years ago
  • 2.3.0 [deprecated]           ...           4 years ago
  • 2.2.4 [deprecated]           ...           4 years ago
  • 2.2.3 [deprecated]           ...           4 years ago
  • 2.2.2 [deprecated]           ...           4 years ago
  • 2.2.1 [deprecated]           ...           4 years ago
  • 2.2.0 [deprecated]           ...           4 years ago
  • 2.1.4 [deprecated]           ...           4 years ago
  • 2.1.3 [deprecated]           ...           4 years ago
  • 2.1.2 [deprecated]           ...           4 years ago
  • 2.1.1 [deprecated]           ...           4 years ago
  • 2.1.0 [deprecated]           ...           4 years ago
  • 2.0.0 [deprecated]           ...           4 years ago
  • 1.0.0 [deprecated]           ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 2
Last Month 8
Dev Dependencies (8)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |