Package Exports
- @comandeer/rollup-lib-bundler
- @comandeer/rollup-lib-bundler/dist/rollup-lib-bundler.es2015.js
- @comandeer/rollup-lib-bundler/dist/rollup-lib-bundler.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@comandeer/rollup-lib-bundler) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@comandeer/rollup-lib-bundler
Super opinionated library bundler using Rollup, Babel and terser.
Installation
npm install @comandeer/rollup-lib-bundler --save-devUsage
Just make it a npm script:
"scripts": {
"build": "rlb"
}Configuration
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,versionandlicenseto create beautiful banner comment,exports.import,moduleorjsnext:mainfor saving ESM bundle,exports.requireormainto 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/
|- 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.mappackage.jsonis in the root of the package (the only bit we all agree on!),src/directory contains package's source,index.jsis the main entrypoint of the package,some-other-chunk.jsis 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,
- ESM output:
src/chunk.js:- ESM output:
dist/chunk.mjs, - CJS output:
dist/chunk.cjs.
- ESM output:
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. ./chunk → src/chunk.js). The only exception is the . subpath, which is translated to src/index.js.
License
See LICENSE file for details.