Prepublish is a solution for simplifying pre-publishing typical JavaScript projects for publishing to NPM.
Prepublish includes two transpiler configurations:
- Buble: Blazing fast ES2015+ transpiler where the goal is to have lightweight runtime code, too.
- Babel: Configuration of Babel transpiler. Supports all of ES2015/ES2016/ES2017. Plus some ES3 helpers for maximum engine compatibility. Plus Support for Object-Rest-Spread and Class Properties. The High-performance async engine with support for generators and async/await powered by fast-async is enabled by default. It requires nodent-runtime. Uses Transform-Runtime to externalize requirements to Polyfills. Resulting code needs all Polyfills for each library published with this tool. Typically by using services like polyfill.io or Babel Runtime aka CoreJS.
Prepublish produces builds depending on the entries of your packages package.json
. It supports
building for CommonJS and well as producing output with ES Modules (ESM). Just add the relevant entries to
the configuration.
- CommonJS Output:
main
- ES Module Output:
module
(jsnext:main
is deprecated)
To offer separate NodeJS and Browser builds use one of the following keys for the browser bundle: browser
or web
or browserify
. These bundles are always exported as ES Modules (ESM) as we have the assumption that they are bundled by another tool like Webpack or Rollup before usage.
67m8BAQAg4mc
You are able to export modules for either ES2015 compatible environments or even more modern platforms, too. This happens in parallel and typically requires some heavy lifting on the bundling phase with Webpack, too. This is because we are using non-standardized configuration keys in package.json. Typically just append :modern
to your normal targets:
- CommonJS Output for NodeJS with ES2015 kept intact:
main:modern
- ES Modules Output for NodeJS with ES2015 kept intact:
module:modern
- Browser Output as ES Modules with ES2015 kept intact:
browser:modern
While es2015
is exactly a requirement for the client to have full ES2015 support, modern
is more flexible.
We are thinking of updating what we understand as modern
regularly. Currently modern
is not fixed by specific
features.
To make sense of all these new modules it would help to produce two different outputs. One for classic browsers and one for modern browsers. ES2015 enabled features are rapidly catching up in performance. Some features are pretty hard to rework for older browsers like Generators, Async/Await, or even Block Scope. Therefor we think there is no need for sending modern clients the fully transpiled code down the wire. Keep in mind that you have to implement some basic client detection to send one or the other file to the matching client.
BTW: The modern builds make a lot of sense during development as it results in shorter transpiler runtimes.
$ npm install --save-dev prepublish
$ yarn add --dev prepublish
Prepublish comes with a binary which can be called from within your scripts
section
in the package.json
file.
"scripts": {
"prepare": "prepublish"
}
There is also some amount of parameters you can use if the auto detection of your library does not work out correctly.
Options
--entry-node Entry file for NodeJS target [default = auto]
--entry-web Entry file for Browser target [default = auto]
--entry-binary Entry file for Binary target [default = auto]
--output-folder Configure the output folder [default = auto]
-t, --transpiler Chose the transpiler/config to use. Either "babel" or "buble". [default = babel]
-x, --minified Enabled minification of output files
-m, --sourcemap Create a source map file during processing
-v, --verbose Verbose output mode [default = false]
-q, --quiet Quiet output mode [default = false]
- Pull requests and stars are always welcome.
- For bugs and feature requests, please create an issue.
- Pull requests must be accompanied by passing automated tests (
$ npm test
).
Apache License; Version 2.0, January 2004
Copyright 2016-2017
Sebastian Software GmbH