Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

peterjwest/convert-extension

Repository files navigation

convert-extension npm version build status coverage status

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.

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');
})();

About

Convert JS source file extensions and imports

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published