cjs-esm
Another CommonJs transform ESModule lib.
English | 简体中文
Usage
import cjs2esm from 'cjs-esm'
const { code, map } = cjs2esm(`const fs = require('fs')`)
TODO
✅ Nested scope(function-scope) 🚧-🐞
function load(path) {
require(path);
}
↓
function load(path) {
import(path);
}
❌ Dynamic require id
✅ require statement
const foo = require('foo').default
↓
import foo from 'foo';
const foo = require('foo')
↓
import * as foo from 'foo';
const foo = require('foo').bar
↓
import * as __CJS_import__0__ from 'foo'; const { bar: foo } = __CJS_import__0__;
const foo = [{ bar: require('foo').bar }]
↓
import * as __CJS_import__0__ from 'foo'; const foo = [{ bar: __CJS_import__0__.bar }]
✅ exports statement
module.exports = fn() { };
↓
const __CJS__export_default__ = module.exports = fn() { };
export { __CJS__export_default__ as default }
exports.foo = 'foo';
↓
const __CJS__export_foo__ = (module.exports == null ? {} : module.exports).foo;
export { __CJS__export_foo__ as foo }