cjyes

0.3.1 • Public • Published

cjyes npm version

🔍 see jay, yes! 🎉 / 👨🏻‍💻 see, JS! 👾 / ⚓️ sea JS ⛴

If you're publishing ES Modules, you need to also publish CommonJS versions of those modules.

This isn't to support old browsers or Node versions: even in Node 14, using require() to load a module won't work if it's only available as ESM.

cjyes is the bare minimum fix for this problem. You write ES Modules and fill out a valid package.json, and it'll generate the corresponding CommonJS files pretty much instantly. cjyes takes up 500kb of disk space including its two dependencies.

Usage

The easiest way to use cjyes is to define package exports the way Node 13+ requires:

{
  "main": "index.mjs",
  "exports": {
    "import": "./index.mjs",
    "require": "./dist/index.cjs"
  },
  "scripts": {
    "prepare": "cjyes"
  },
  "devDependencies": {
    "cjyes": "^0.3.0"
  }
}

cjyes will create CommonJS versions of all modules listed in the "exports" field and place them at the specified locations.

You can also use .js file extensions and the {"type":"module"} field - cjyes will detect this and generate the required .cjs output files.

Multiple Entries

Multiple entry points are supported automatically. Simply define them in your export map:

{
  "main": "index.mjs",
  "exports": {
    ".": {
      "import": "./index.mjs",
      "require": "./index.cjs"
    },
    "./jsx": {
      "import": "./jsx.mjs",
      "require": "./jsx.cjs"
    },
    "./hooks": {
      "import": "./hooks/index.mjs",
      "require": "./hooks/index.cjs"
    }
  },
  "scripts": { "prepare": "cjyes" },
  "devDependencies": { "cjyes": "^0.3.0" }
}

Custom Files

It is also possible to pass a list of input modules to cjyes directly:

cjyes src/index.js src/other.mjs
# generates the following: 
# dist/ 
#    index.cjs 
#    other.cjs 

Readme

Keywords

none

Package Sidebar

Install

npm i cjyes

Weekly Downloads

314

Version

0.3.1

License

Apache-2.0

Unpacked Size

6.43 kB

Total Files

3

Last publish

Collaborators

  • developit