diff --git a/.changeset/nervous-months-repeat.md b/.changeset/nervous-months-repeat.md new file mode 100644 index 00000000000..42c7fac2064 --- /dev/null +++ b/.changeset/nervous-months-repeat.md @@ -0,0 +1,5 @@ +--- +"webpack-cli": patch +--- + +perf: enable the Node.js compile cache (`module.enableCompileCache`, available on Node.js >= 22.8.0) to speed up CLI startup diff --git a/packages/webpack-cli/bin/cli.js b/packages/webpack-cli/bin/cli.js index b3a6ca5e11a..6e496b42bb9 100755 --- a/packages/webpack-cli/bin/cli.js +++ b/packages/webpack-cli/bin/cli.js @@ -2,6 +2,18 @@ "use strict"; +// `module.enableCompileCache` is only available on Node.js >= 22.8.0 +// eslint-disable-next-line n/no-unsupported-features/node-builtins +const { enableCompileCache } = require("node:module"); + +if (enableCompileCache) { + try { + enableCompileCache(); + } catch { + // Ignore errors + } +} + // Prefer the local installation of `webpack-cli` when one exists. Run this // before requiring the (heavier) CLI implementation: a delegated run then never // loads it, and `WEBPACK_CLI_SKIP_IMPORT_LOCAL` skips loading `import-local` too.