Dual Publish

Services & Skills

Share on

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

You write CommonJS in your npm library sources:

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

npx dual-publish compiles your library when 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'

Explore more open source projects

Contact us

We’d love to hear from you! We’re not really all that evil, and we love discussing potential projects, intriguing ideas, and new opportunities. Complete the form below or drop us a line at surrender@evilmartians.com. Alternatively, schedule a Calendly appointment with us right now!

Martians at a glance
years in business

A product development consultancy that works with startups and established businesses, while also creating open source-based products and services