mirror of https://github.com/webpack/webpack.git
feat: allow CLI to be ESM
This commit is contained in:
parent
5b20c9af1c
commit
6ce8ad2d7a
|
@ -77,6 +77,13 @@ module.exports = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
overrides: [
|
overrides: [
|
||||||
|
{
|
||||||
|
// Allow to use `dynamic` import
|
||||||
|
files: ["bin/**/*.js"],
|
||||||
|
parserOptions: {
|
||||||
|
ecmaVersion: 2020
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
files: ["lib/**/*.runtime.js", "hot/*.js"],
|
files: ["lib/**/*.runtime.js", "hot/*.js"],
|
||||||
env: {
|
env: {
|
||||||
|
|
|
@ -78,8 +78,19 @@ const runCli = cli => {
|
||||||
const pkgPath = require.resolve(`${cli.package}/package.json`);
|
const pkgPath = require.resolve(`${cli.package}/package.json`);
|
||||||
// eslint-disable-next-line node/no-missing-require
|
// eslint-disable-next-line node/no-missing-require
|
||||||
const pkg = require(pkgPath);
|
const pkg = require(pkgPath);
|
||||||
|
|
||||||
|
if (pkg.type === "module" || /\.mjs/i.test(pkg.bin[cli.binName])) {
|
||||||
|
// eslint-disable-next-line node/no-unsupported-features/es-syntax
|
||||||
|
import(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName])).catch(
|
||||||
|
error => {
|
||||||
|
console.error(error);
|
||||||
|
process.exitCode = 1;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
// eslint-disable-next-line node/no-missing-require
|
// eslint-disable-next-line node/no-missing-require
|
||||||
require(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName]));
|
require(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName]));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue