0.3.0 • Published 4 years ago
convert-extension v0.3.0
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-extensionor
yarn add convert-extensionUsage
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=xyzProgrammatic 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');
})();