From b89df1d8c8c9c6cb5c60acf89bb8e6d54a1568c6 Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 4 Nov 2024 16:23:55 +0800 Subject: [PATCH] perf(cli): enable Node.js compile cache (#8331) * perf(cli): enable Node.js compile cache * fix: no need for NODE_DISABLE_COMPILE_CACHE --- packages/rspack-cli/bin/rspack.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/rspack-cli/bin/rspack.js b/packages/rspack-cli/bin/rspack.js index 1b1c557b82a..1510c6b18dc 100755 --- a/packages/rspack-cli/bin/rspack.js +++ b/packages/rspack-cli/bin/rspack.js @@ -1,4 +1,17 @@ #!/usr/bin/env node +const nodeModule = require("node:module"); + +// enable on-disk code caching of all modules loaded by Node.js +// requires Nodejs >= 22.8.0 +const { enableCompileCache } = nodeModule; +if (enableCompileCache) { + try { + enableCompileCache(); + } catch { + // ignore errors + } +} + const { RspackCLI } = require("../dist/index"); async function runCLI() {