cjyes
#
🔍 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
.jsfile extensions and the{"type":"module"}field - cjyes will detect this and generate the required.cjsoutput 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