Prepublish includes two transpiler configurations:
Prepublish produces exports of your sources depending on the entries of your packages
package.json. It supports
building for CommonJS and well as with ES Modules (ESM). Just add the relevant entries to
To offer separate NodeJS and Browser builds use one of the following keys for the browser bundle:
web. 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.
You might wonder how to produce a browser bundle from a different input. This is actually pretty easy. Your package just have to follow this convention.
The files are looked up for an order. The first match is being used.
You are able to export modules for either ES5 compatible environments or for more modern platforms, too.
Note: To use these non-standard bundle outputs requires some tweaks on the bundling phase of the application, too (e.g. in Webpack). This is because we are using non-standardized configuration keys in package.json. Typically just append either
:modern to your normal targets:
es2015 is exactly a requirement for the client to have full ES2015 support,
modern is even more modern adding things from ES2017 to the list like
await. Modern is regularly updated inside our Babel Preset. It is by no way a never changing stable target.
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 ES2015-capable 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.
prepublish is capable in generating for binary targets.
This generates a
mypackage binary which is generated from the matching source file.
Binaries are generally generated from one of these source files:
There is a new option to explicitely target Node v8 when generating binaries. This is controlled via the following command line argument:
prepublish --target-modern together with the
bin entry for
package.json as seen before.
$ 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
There is also some amount of parameters you can use if the auto detection of your library does not work out correctly.
Usage $ prepublish 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 to use. Either "babel" or "buble". [default = babel] -x, --minified Enabled minification of output files -m, --sourcemap Create a source map file during processing --target-modern Binaries should target Node v8 LTS instead of Node v6 LTS. -v, --verbose Verbose output mode [default = false] -q, --quiet Quiet output mode [default = false]
Sebastian Software GmbH