stealjs / transpile

Transpiles from everything to everything else
https://www.npmjs.com/package/transpile
MIT License
25 stars 10 forks source link

Add CJS -> ESM transpiler #73

Open matthewp opened 7 years ago

matthewp commented 7 years ago

Add a transpile that will transpile CommonJS to ESM format.

"use strict";

var foo = require("foo");

module.exports = foo;

becomes:

import foo from "foo";

export default foo;
matthewp commented 7 years ago

By default this should only work with strict mode modules. Those that have "use strict"; at the top of the file. If transpile encounters any module that's not strict mode it should throw as it is impossible to guarantee the module will work once converted to ES format.

To work around this, allow an { unsafe: true } option that ignores whether strict mode is there or not.