dual-publish

Publish project as dual ES modules and CommonJS package

MIT 44 个版本
安装
npm install dual-publish
yarn add dual-publish
pnpm add dual-publish
bun add dual-publish
README

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'
Sponsored by Evil Martians

Docs

Read full docs here.

版本列表
4.0.0 2023-11-03
3.0.1 2022-03-28
3.0.0 2022-01-19
2.0.2 2021-10-17
2.0.1 2021-10-13
2.0.0 2021-09-26
1.0.9 2021-09-21
1.0.8 2021-08-12
1.0.7 2021-08-12
1.0.6 2021-08-11
1.0.5 2021-03-15
1.0.4 2021-03-09
1.0.3 2020-11-20
1.0.2 2020-11-19
1.0.1 2020-11-19
1.0.0 2020-11-19
0.11.0 2020-07-03
0.10.6 2020-06-23
0.10.5 2020-06-18
0.10.4 2020-06-18
0.10.3 2020-06-11
0.10.2 2020-05-06
0.10.1 2020-04-18
0.10.0 2020-04-10
0.9.0 2020-04-10
0.8.7 2020-04-01
0.8.6 2020-03-25
0.8.5 2020-03-23
0.8.4 2020-03-22
0.8.3 2020-03-21
0.8.2 2020-03-21
0.8.1 2020-03-21
0.8.0 2020-03-21
0.7.0 2020-03-21
0.6.1 2020-03-20
0.6.0 2020-03-20
0.5.2 2020-03-15
0.5.1 2020-03-14
0.5.0 2020-03-07
0.4.1 2020-03-06
0.4.0 2020-03-05
0.3.0 2020-03-01
0.2.0 2020-02-21
0.1.0 2020-02-17