Warning
This project has been archived, because this is no longer necessary with modern JS build tools.
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.
npm install convert-extensionor
yarn add convert-extensionRun 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=xyzimport 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 });
})();const convertExtension = require('convert-extension');
(async function() {
await convertExtension('build/', 'mjs', 'js');
})();