4.0.0 • Published 6 months ago

dual-publish v4.0.0

Weekly downloads
26
License
MIT
Repository
github
Last release
6 months ago

Dual Publish

Publish JS project as dual ES modules and CommonJS package to npm.

  • Tested on projects with 16M downloads per month.
  • CI tests with it works with Node.js, browsers, React Native, bundlers (webpack, Parcel, Rollup, or esbuild) and CDNs (like jspm).
  • Does not change line numbers in stacktrace and keep sources readable.
  • No build step. No need for separated src/ and dist/ dirs in repository. You will be able to test branch by installing version from GitHub like npm i example@you/example#fix.
  • Multiple files support. Your user will be able to import separated files like import { nanoid } from 'nanoid/async'.
  • Cleans npm package from development configs before publishing.
  • Supports process.env.NODE_ENV for development checks, which you want to remove in production JS bundle.

You write CommonJS in your npm library sources:

// index.js
module.exports = { lib }

npx dual-publish compiles your library during publishing to npm:

// index.js
export { lib }

// index.cjs
module.exports = { lib }

// package.json
{
  …
  "type": "module",
  "module": "index.js",
  "main": "index.cjs",
  "exports": {
    "require": "./index.cjs",
    "import": "./index.js"
  }
}

Now your library can be imported natively as ESM or CommonJS:

// CommonJS
let { lib } = require('lib')

// ESM in Node.js, webpack, Parcel, and Rollup
import { lib } from 'lib'

// ESM in browser
import { lib } from 'https://cdn.jsdelivr.net/npm/lib/index.js'

Docs

Read full docs here.

4.0.0

6 months ago

3.0.1

2 years ago

3.0.0

2 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.11.0

4 years ago

0.10.6

4 years ago

0.10.4

4 years ago

0.10.5

4 years ago

0.10.3

4 years ago

0.10.2

4 years ago

0.10.1

4 years ago

0.10.0

4 years ago

0.9.0

4 years ago

0.8.7

4 years ago

0.8.6

4 years ago

0.8.5

4 years ago

0.8.4

4 years ago

0.8.3

4 years ago

0.8.2

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago

0.7.0

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago