Simple library bundler


1330.16.02 months ago5 years agoMinified + gzip package size for @comandeer/rollup-lib-bundler in KB



Build Status codecov npm (scoped)

Super opinionated library bundler using Rollup, Babel and terser.


npm install @comandeer/rollup-lib-bundler --save-dev


Just make it a npm script:

"scripts": {
    "build": "rlb"


No configuration. Consider it a feature.

How does it work?

It gets package.json from the current working directory, parses it and get neeeded info:

  • name, author, version and license to create beautiful banner comment,
  • exports.import, module or jsnext:main for saving ESM bundle,
  • exports.require or main to get path for saving CJS bundle (optional).

Then the bundling happens. The default entry point for Rollup is src/index.js. Please note that dist/ directory is purged before bundling! So if anything should be there alongside the bundle, it should be added there after the bundling.

Assumed file structure

This is very opinionated bundler and it assumes that the project's file structure looks like the one below:

|- package.json
|- src/
|     |- index.js
|     |- some-other-chunk.js
|- dist/
|      |- bundled-index.cjs
|      |- bundled-index.cjs.map
|      |- bundled-index.mjs
|      |- bundled-index.mjs.map
|      |- bundled-some-other-chunk.cjs
|      |- bundled-some-other-chunk.cjs.map
|      |- bundled-some-other-chunk.mjs
|      |- bundled-some-other-chunk.mjs.map
  • package.json is in the root of the package (the only bit we all agree on!),
  • src/ directory contains package's source,
    • index.js is the main entrypoint of the package,
    • some-other-chunk.js is the optional additional entrypoint (see [#mutliple-bundles](Multiple bundles) section for more info),
  • dist/ directory contains bundled code.

Multiple bundles

By default, src/index.js is treated as the only entry point. However, using subpath exports you can create several bundled chunks/files. Example:

"exports": {
    ".": {
        "require": "./dist/es5.cjs",
        "import": "./dist/es6.mjs"

    "./chunk": {
        "require": "./dist/chunk.cjs",
        "import": "./dist/chunk.mjs"

In this case two source files will be bundled:

  • src/index.js:
    • ESM output: dist/es6.mjs,
    • CJS output: dist/es5.cjs,
  • src/chunk.js:
    • ESM output: dist/chunk.mjs,
    • CJS output: dist/chunk.cjs.

Although Node.js supports several different syntaxes for subpath exports, this bundler supports only the form presented on the example above (so each subpath needs two properties – require for CJS bundle and import for ESM bundle).

Each subpath is translated to appropriate file in src directory. Basically, ./ at the beginning is translated to src/ and the name of the subpath is translated to <subpath>.js (e.g. ./chunksrc/chunk.js). The only exception is the . subpath, which is translated to src/index.js.


See LICENSE file for details.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.