@putout/plugin-convert-commonjs-to-esm
putout
plugin adds ability to convert Commonjs to ESM.
Install
npm i @putout/plugin-convert-commonjs-to-esm -D
Rule
{
"rules": {
"convert-commonjs-to-esm/require": "on",
"convert-commonjs-to-esm/exports": "on",
"convert-commonjs-to-esm/commons": "on"
}
}
require
❌ Incorrect code example
const {join} = require('path');
module.exports = () => {
};
✅ Correct code Example
import {join} from 'path';
export default () => {
};
exports
❌ Incorrect code example
module.exports = () => {
};
✅ Correct code Example
export default () => {
};
Commons
❌ Incorrect code example
await readFile(__filename);
✅ Correct code Example
import {createCommons} from 'simport';
const {__filename} = createCommons(import.meta.url);
await readFile(__filename);
License
MIT