modconv
Module conversion tool for node.
Usage
modconv -d dist src
modconv
does one thing, convert from one js module syntax to another. It uses Babel behind the scenes and has a very small set of flags you can use.
Why use this?
The main thing this tool does that many other module conversion tools do not is handle default exports from ECMAScript 6 module (esm) format when producing CommonJS (cjs) output. Normally you end up doing something like this from your converted modules:
const myModule = require('my-module').default;
This still works, but leaving off the .default
part also works. That means you can simply require converted modules like this, and they will work as expected:
const myModule = require('my-module');
It's very useful for published modules that are written in esm, since using the cjs version in node feels very natural. (Note that other target module formats do not work this way, only cjs).
This is all thanks to babel-plugin-add-module-exports.
Options
Flag | Description |
---|---|
--help | Show help information |
-f, --format | Desired output format, see --help for available formats |
-d, --out-dir | Target directory for all converted code to be written |
-o, --out-file | Target file for all converted code to be written |
--silent | Prevent status output, converted module will still be sent to stdout if -d or -o are not used |
License
MIT © w33ble