convert-extension
v0.3.0
Published
Convert JS source file extensions and imports
Downloads
183
Maintainers
Readme
convert-extension
Convert JS source file extensions and imports.
This module was created to allow you to convert the output of Typescript to .mjs
or .cjs
, for better support with node ES6 modules.
Installation
npm install convert-extension
or
yarn add convert-extension
Usage
Run the command, providing a file extension (here mjs
) and a directory:
npx convert-extension mjs build/
This will convert any .js
files and their relative imports to .mjs
. It will also convert source maps, if they exist.
You can also specify a custom extension of input files with --input-extension
:
npx convert-extension mjs build/ --input-extension=xyz
Programmatic usage
import convertExtension from 'convert-extension';
(async function() {
await convertExtension('build/', 'mjs', 'js');
})();
You can also supply Babel transform options as a fourth argument:
import convertExtension from 'convert-extension';
(async function() {
await convertExtension('build/', 'mjs', 'js', { minified: true });
})();
With CommonJS / require()
const convertExtension = require('convert-extension');
(async function() {
await convertExtension('build/', 'mjs', 'js');
})();