Code Monkey home page Code Monkey logo

rollup-babel-lib-bundler's Introduction

rollup-babel-lib-bundler

This project has been deprecated! Please use microbundle or tsdx instead.

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

rollup-babel-lib-bundler's People

Contributors

frostney avatar amaldare93 avatar bfred-it avatar

Stargazers

Charles Jacquin avatar Alexandre Bonaventure Geissmann avatar buzzzzz avatar Tim Kendall avatar Jinghui Chen avatar Brad Pillow avatar Eric Bailey avatar Sven Lito avatar James Yang avatar Chia-liang Kao avatar Matt Travi avatar Tomasz Jakut avatar Ilya Ayzenshtok avatar Ahmed Abbas avatar Paul Le Cam avatar Johnie Hjelm avatar Brian Lai avatar Pete Wynn avatar Joe Kane avatar Henning Leutz avatar

Watchers

 avatar James Cloos avatar

Forkers

amaldare93

rollup-babel-lib-bundler's Issues

Duplicate messages

Only display them as a single message or with an indicator afterwards.

Unit test for CLI

Add some unit tests for the command-line interface itself to ckeck if options are passed correctly.

Uglify option

Add an option to generate a .min.js build for the UMD version.

Bundle dependencies

If libraries are found in bundleDependencies of package.json, they should automatically be included in the resulting bundle, making it easier to configure all-in-one bundles.

Use AVA test runner

I'm very much a fan of AVA and once #5 is done, I feel the tests should use AVA instead.

Use `jsnext:main` if available

When using the command-line tool, it should automatically check for jsnext:main and use this entry as the entrypoint by default if no entry point has been declared by the user.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.