1 | # rollup-babel-lib-bundler
|
2 | Utility to bundle JavaScript libraries with Rollup
|
3 |
|
4 | [![Build Status](https://travis-ci.org/frostney/rollup-babel-lib-bundler.svg?branch=master)](https://travis-ci.org/frostney/rollup-babel-lib-bundler) [![Dependency Status](https://david-dm.org/frostney/rollup-babel-lib-bundler.svg)](https://david-dm.org/frostney/rollup-babel-lib-bundler) [![devDependency Status](https://david-dm.org/frostney/rollup-babel-lib-bundler/dev-status.svg)](https://david-dm.org/frostney/rollup-babel-lib-bundler#info=devDependencies) [![Coverage Status](https://coveralls.io/repos/github/frostney/rollup-babel-lib-bundler/badge.svg?branch=master)](https://coveralls.io/github/frostney/rollup-babel-lib-bundler?branch=master)
|
5 |
|
6 | 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.
|
7 | (Ideally, it should pick up my Babel config and the library name from the `package.json`.)
|
8 |
|
9 | 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.
|
10 |
|
11 | 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.
|
12 |
|
13 | ## Installation
|
14 | ```
|
15 | $ npm install rollup-babel-lib-bundler
|
16 | ```
|
17 |
|
18 | ## Usage
|
19 |
|
20 | Rollup requires a rollup-compatible Babel config. Simply change the `es2015` preset to `es2015-rollup` or `es2015-loose` to `es2015-loose-rollup`.
|
21 |
|
22 | ![usage](https://github.com/frostney/rollup-babel-lib-bundler/blob/master/docs/usage.gif)
|
23 |
|
24 | ### Command-line
|
25 | ```
|
26 | rollup-babel-lib-bundler ./myFancyLibrary.js
|
27 | ```
|
28 |
|
29 | ### JavaScript API
|
30 | The API is very similar to a Rollup config file. In fact, additional options will be passed into Rollup.
|
31 |
|
32 | ```javascript
|
33 | var rollupBabelLibBundler = require('rollup-babel-lib-bundler');
|
34 |
|
35 | rollupBabelLibBundler({
|
36 | name: 'myfancylibrary',
|
37 | moduleName: 'myFancyLibrary',
|
38 | dest: 'dist',
|
39 | entry: './myFancyLibrary.js',
|
40 | format: ['cjs', 'umd', 'es6'],
|
41 | });
|
42 | ```
|
43 |
|
44 | #### options.name
|
45 | ###### Type: `String`
|
46 | ###### Default: `mylibrary`
|
47 | The name of the library. Will be used for the generated filenames.
|
48 |
|
49 | #### options.moduleName
|
50 | ###### Type: `String`
|
51 | ###### Default `myLibrary`
|
52 | 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.
|
53 |
|
54 | #### options.dest
|
55 | ###### Type: `String`
|
56 | ###### Default `dist`
|
57 | The directory where the files will be generated to.
|
58 |
|
59 | #### options.entry
|
60 | ###### Type: `String`
|
61 | ###### Default `index.js`
|
62 | The path to the library itself.
|
63 |
|
64 | #### options.format
|
65 | ###### Type: `Array`
|
66 | ###### Default `['umd', 'es6', 'cjs']`
|
67 | Can be `umd`, `es6`, `cjs`, `iife` or a combination of these.
|
68 |
|
69 | #### Return value
|
70 | ###### Type: `Promise`
|
71 | This returns a promise with an array of objects which have the following format:
|
72 |
|
73 | ```javascript
|
74 | {
|
75 | name: String, // The module name
|
76 | format: String, // The module format (es6, umd, cjs)
|
77 | endTime: Number, // The time where this module finished generating
|
78 | startTime: Number, // The time before the generating process started
|
79 | }
|
80 | ```
|
81 |
|
82 | ## License
|
83 | MIT
|