prepublish

Simplifies the prepare step (bundling, transpiling, rebasing) during publishing NPM packages.

This package is no longer maintained. Please use Preppy https://www.npmjs.com/package/preppy instead.
Last updated 7 years ago by swernerx .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ npm install prepublish 
SYNC missed versions from official npm registry.

Prepublish
Sponsored by Version Downloads Build Status Unix Build Status Windows Dependencies

Prepublish is a solution for simplifying pre-publishing typical JavaScript projects for publishing to NPM.

Transpilers

Prepublish relies on the Babel Preset Edge for producing forward-looking optimistic code for your code base.

Output Targets

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 the configuration.

  • CommonJS Output: main
  • ESM Output: module

Basic Example:

{
  "name": "mypackage",
  "main": "lib/main.cjs.js",
  "module": "lib/main.esm.js"
}

To offer separate NodeJS and Browser builds use one of the following keys for the browser bundle: browser or 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.

Example:

{
  "name": "mypackage",
  "main": "lib/main.cjs.js",
  "module": "lib/main.esm.js",
  "browser": "lib/main.browser.js"
}

Input Entries

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.

Entries for NodeJS targets

  • src/node/public.js
  • src/node/export.js
  • src/node.js
  • src/server/public.js
  • src/server/export.js
  • src/server.js
  • src/server.js
  • src/public.js
  • src/export.js
  • src/index.js

Sources for the Browser targets

  • src/web/public.js
  • src/web/export.js
  • src/web.js
  • src/browser/public.js
  • src/browser/export.js
  • src/browser.js
  • src/client/public.js
  • src/client/export.js
  • src/client.js

Sources for binary targets

  • src/cli.js
  • src/binary.js
  • src/script.js

Targetting ES2015

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 :es2015 or :modern to your normal targets:

  • CommonJS Output for NodeJS with ES2015 kept intact: main:es2015
  • ES Modules Output for NodeJS with ES2015 kept intact: module:es2015
  • Browser Output as ES Modules with ES2015 kept intact: browser:es2015

While 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 async/await. Modern is regularly updated inside our Babel Preset. It is by no way a never changing stable target.

Example Configuration:

{
  "name": "mypackage",
  "main": "lib/main-cjs.js",
  "module": "lib/main-esm.js",
  "browser": "lib/main-browser.js",
  "main:es2015": "lib/main.cjs.es2015.js",
  "module:es2015": "lib/main.esm.es2015.js",
  "browser:es2015": "lib/main.browser.es2015.js"
}

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.

Binary Output

Additionally prepublish is capable in generating for binary targets.

This generates a mypackage binary which is generated from the matching source file.

Binaries are generated from one of these source files:

  • src/cli.js
  • src/binary.js
  • src/script.js

Example Configuration:

{
  "name": "mypackage",
  "bin": {
    "mypackage": "bin/mypackage"
  }
}

Prepublish automatically choses the matching NodeJS version from your engines configuration:

"engines": {
  "node": ">=6.0.0",
  "npm": ">=5.0.0",
  "yarn": ">=1.0.0"
}

inside your package.json. This example configuration targets any version of NodeJS matching at least the v6 capabilities.

Related Content

Installation

NPM

$ npm install --save-dev prepublish

Yarn

$ yarn add --dev prepublish

Usage

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.

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]

  -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]

License

Apache License; Version 2.0, January 2004

Copyright

Logo of Sebastian Software GmbH, Mainz, Germany

Copyright 2016-2018
Sebastian Software GmbH

Current Tags

  • 2.2.0                                ...           latest (6 years ago)

70 Versions

  • 2.2.0 [deprecated]           ...           6 years ago
  • 2.1.2 [deprecated]           ...           6 years ago
  • 2.1.1 [deprecated]           ...           6 years ago
  • 2.1.0 [deprecated]           ...           6 years ago
  • 2.0.0 [deprecated]           ...           6 years ago
  • 1.7.0 [deprecated]           ...           7 years ago
  • 1.6.3 [deprecated]           ...           7 years ago
  • 1.6.2 [deprecated]           ...           7 years ago
  • 1.6.1 [deprecated]           ...           7 years ago
  • 1.6.0 [deprecated]           ...           7 years ago
  • 1.5.4 [deprecated]           ...           7 years ago
  • 1.5.3 [deprecated]           ...           7 years ago
  • 1.5.2 [deprecated]           ...           7 years ago
  • 1.5.1 [deprecated]           ...           7 years ago
  • 1.5.0 [deprecated]           ...           7 years ago
  • 1.4.3 [deprecated]           ...           7 years ago
  • 1.4.2 [deprecated]           ...           7 years ago
  • 1.4.1 [deprecated]           ...           7 years ago
  • 1.4.0 [deprecated]           ...           7 years ago
  • 1.3.0 [deprecated]           ...           7 years ago
  • 1.2.7 [deprecated]           ...           7 years ago
  • 1.2.6 [deprecated]           ...           7 years ago
  • 1.2.5 [deprecated]           ...           7 years ago
  • 1.2.4 [deprecated]           ...           7 years ago
  • 1.2.3 [deprecated]           ...           7 years ago
  • 1.2.2 [deprecated]           ...           7 years ago
  • 1.2.1 [deprecated]           ...           7 years ago
  • 1.2.0 [deprecated]           ...           7 years ago
  • 1.1.3 [deprecated]           ...           7 years ago
  • 1.1.2 [deprecated]           ...           7 years ago
  • 1.1.1 [deprecated]           ...           7 years ago
  • 1.1.0 [deprecated]           ...           7 years ago
  • 1.0.6 [deprecated]           ...           7 years ago
  • 1.0.5 [deprecated]           ...           7 years ago
  • 1.0.4 [deprecated]           ...           7 years ago
  • 1.0.3 [deprecated]           ...           7 years ago
  • 1.0.2 [deprecated]           ...           7 years ago
  • 1.0.1 [deprecated]           ...           7 years ago
  • 1.0.0 [deprecated]           ...           7 years ago
  • 0.20.1 [deprecated]           ...           7 years ago
  • 0.20.0 [deprecated]           ...           7 years ago
  • 0.19.1 [deprecated]           ...           7 years ago
  • 0.19.0 [deprecated]           ...           7 years ago
  • 0.18.0 [deprecated]           ...           7 years ago
  • 0.17.0 [deprecated]           ...           7 years ago
  • 0.16.3 [deprecated]           ...           8 years ago
  • 0.16.2 [deprecated]           ...           8 years ago
  • 0.16.1 [deprecated]           ...           8 years ago
  • 0.16.0 [deprecated]           ...           8 years ago
  • 0.15.4 [deprecated]           ...           8 years ago
  • 0.15.3 [deprecated]           ...           8 years ago
  • 0.15.2 [deprecated]           ...           8 years ago
  • 0.15.1 [deprecated]           ...           8 years ago
  • 0.15.0 [deprecated]           ...           8 years ago
  • 0.14.3 [deprecated]           ...           8 years ago
  • 0.14.2 [deprecated]           ...           8 years ago
  • 0.14.1 [deprecated]           ...           8 years ago
  • 0.14.0 [deprecated]           ...           8 years ago
  • 0.13.5 [deprecated]           ...           8 years ago
  • 0.13.4 [deprecated]           ...           8 years ago
  • 0.13.3 [deprecated]           ...           8 years ago
  • 0.13.2 [deprecated]           ...           8 years ago
  • 0.13.1 [deprecated]           ...           8 years ago
  • 0.13.0 [deprecated]           ...           8 years ago
  • 0.12.5 [deprecated]           ...           8 years ago
  • 0.12.4 [deprecated]           ...           8 years ago
  • 0.12.2 [deprecated]           ...           8 years ago
  • 0.12.1 [deprecated]           ...           8 years ago
  • 0.12.0 [deprecated]           ...           8 years ago
  • 0.0.0 [deprecated]           ...           10 years ago
Maintainers (1)
Downloads
Total 56
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dev Dependencies (4)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE