From 34ce74cbf100b50113b7ac82a8cda190bc01c2e3 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sun, 8 Jun 2025 20:10:57 +0100 Subject: [PATCH 1/2] perf: enable node compile cache --- packages/nuxi/bin/nuxi.mjs | 17 ++++++++++++++++- packages/nuxt-cli/bin/nuxi.mjs | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/packages/nuxi/bin/nuxi.mjs b/packages/nuxi/bin/nuxi.mjs index 08683cf73..054a125cb 100755 --- a/packages/nuxi/bin/nuxi.mjs +++ b/packages/nuxi/bin/nuxi.mjs @@ -1,7 +1,19 @@ #!/usr/bin/env node +import nodeModule from 'node:module' +import process from 'node:process' import { fileURLToPath } from 'node:url' -import { runMain } from '../dist/index.mjs' + +// https://nodejs.org/api/module.html#moduleenablecompilecachecachedir +// https://github.com/nodejs/node/pull/54501 +if (nodeModule.enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) { + try { + nodeModule.enableCompileCache() + } + catch { + // Ignore errors + } +} globalThis.__nuxt_cli__ = { startTime: Date.now(), @@ -9,4 +21,7 @@ globalThis.__nuxt_cli__ = { devEntry: fileURLToPath(new URL('../dist/dev/index.mjs', import.meta.url)), } +// eslint-disable-next-line antfu/no-top-level-await +const { runMain } = await import('../dist/index.mjs') + runMain() diff --git a/packages/nuxt-cli/bin/nuxi.mjs b/packages/nuxt-cli/bin/nuxi.mjs index 08683cf73..054a125cb 100755 --- a/packages/nuxt-cli/bin/nuxi.mjs +++ b/packages/nuxt-cli/bin/nuxi.mjs @@ -1,7 +1,19 @@ #!/usr/bin/env node +import nodeModule from 'node:module' +import process from 'node:process' import { fileURLToPath } from 'node:url' -import { runMain } from '../dist/index.mjs' + +// https://nodejs.org/api/module.html#moduleenablecompilecachecachedir +// https://github.com/nodejs/node/pull/54501 +if (nodeModule.enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) { + try { + nodeModule.enableCompileCache() + } + catch { + // Ignore errors + } +} globalThis.__nuxt_cli__ = { startTime: Date.now(), @@ -9,4 +21,7 @@ globalThis.__nuxt_cli__ = { devEntry: fileURLToPath(new URL('../dist/dev/index.mjs', import.meta.url)), } +// eslint-disable-next-line antfu/no-top-level-await +const { runMain } = await import('../dist/index.mjs') + runMain() From f2ee0edcf874359b308ec9068800e06a946bd1de Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 11 Jun 2025 12:23:04 +0200 Subject: [PATCH 2/2] perf: use node compile cache if available --- packages/nuxi/bin/nuxi.mjs | 4 +++- packages/nuxt-cli/bin/nuxi.mjs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/nuxi/bin/nuxi.mjs b/packages/nuxi/bin/nuxi.mjs index 054a125cb..31d54504d 100755 --- a/packages/nuxi/bin/nuxi.mjs +++ b/packages/nuxi/bin/nuxi.mjs @@ -8,7 +8,9 @@ import { fileURLToPath } from 'node:url' // https://github.com/nodejs/node/pull/54501 if (nodeModule.enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) { try { - nodeModule.enableCompileCache() + const { directory } = nodeModule.enableCompileCache() + // allow child process to share the same cache directory + process.env.NODE_COMPILE_CACHE ||= directory } catch { // Ignore errors diff --git a/packages/nuxt-cli/bin/nuxi.mjs b/packages/nuxt-cli/bin/nuxi.mjs index 054a125cb..31d54504d 100755 --- a/packages/nuxt-cli/bin/nuxi.mjs +++ b/packages/nuxt-cli/bin/nuxi.mjs @@ -8,7 +8,9 @@ import { fileURLToPath } from 'node:url' // https://github.com/nodejs/node/pull/54501 if (nodeModule.enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) { try { - nodeModule.enableCompileCache() + const { directory } = nodeModule.enableCompileCache() + // allow child process to share the same cache directory + process.env.NODE_COMPILE_CACHE ||= directory } catch { // Ignore errors