Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

WebReflection/dualmodule

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js Dual Modules

Abandoned: this module is now much better via modulestrap.


The minimal amount of effort needed to publish modules, for both ESM and CJS, without ever needing to write an .mjs, or .cjs file.

Test It !

You need node 13.10 or higher, and a test folder, such as ~/test/node-modules to perform this test:

mkdir -p ~/test/node-modules
cd ~/test/node-modules
npm i dualmodule
# test CommonJS
node -e 'console.log(require("dualmodule"))'; # read "CJS"
# test ESM
node --input-type=module -e 'import $ from "dualmodule"; console.log($)';

If you are in node < 13.10 you'll see an ExperimentalWarning, but the output is ESM.

If you are in node >= 13.10 you won't see the warning, just the ESM output.

If you'd like to test through any file.js in that folder, and you want to test the ESM version of the module:

echo '{"type":"module"}' > ~/test/node-modules/package.json
echo 'import $ from "dualmodule"; console.log($)' > test.js
node test.js # read "ESM"

And you are good to go 🎉

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published