Skip to content

Commit bb4a5d9

Browse files
authored
feat: allow CLI to be ESM (#4837)
1 parent 53bb4d7 commit bb4a5d9

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

bin/webpack-dev-server.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,18 @@ const runCli = (cli) => {
8585
const pkgPath = require.resolve(`${cli.package}/package.json`);
8686
// eslint-disable-next-line import/no-dynamic-require
8787
const pkg = require(pkgPath);
88-
// eslint-disable-next-line import/no-dynamic-require
89-
require(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName]));
88+
89+
if (pkg.type === "module" || /\.mjs/i.test(pkg.bin[cli.binName])) {
90+
import(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName])).catch(
91+
(error) => {
92+
console.error(error);
93+
process.exitCode = 1;
94+
}
95+
);
96+
} else {
97+
// eslint-disable-next-line import/no-dynamic-require
98+
require(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName]));
99+
}
90100
};
91101

92102
/**

0 commit comments

Comments
 (0)