From 327cb8e41229c5a4fd72c987d98c42ed9f83297f Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 19 Nov 2024 17:33:42 +0100 Subject: [PATCH 1/2] fix(node-cluster): create dedicated chunk for worker --- src/presets/node/preset.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/presets/node/preset.ts b/src/presets/node/preset.ts index b2cc1d346c..8573733ddb 100644 --- a/src/presets/node/preset.ts +++ b/src/presets/node/preset.ts @@ -1,4 +1,6 @@ import { defineNitroPreset } from "nitropack/kit"; +import { normalize } from "pathe"; +import { resolvePathSync } from "mlly"; const node = defineNitroPreset( { @@ -30,6 +32,22 @@ const nodeCluster = defineNitroPreset( { extends: "node-server", entry: "./runtime/node-cluster", + hooks: { + "rollup:before"(_nitro, rollupConfig) { + const manualChunks = rollupConfig.output?.manualChunks; + if (manualChunks && typeof manualChunks === "function") { + const clusterEntry = resolvePathSync("./runtime/node-server", { + url: import.meta.url, + }); + rollupConfig.output.manualChunks = (id, meta) => { + if (id.includes("node-server") && normalize(id) === clusterEntry) { + return "nitro/node-worker"; + } + return manualChunks(id, meta); + }; + } + }, + }, }, { name: "node-cluster" as const, From d3b8ac7abf03f1b9ab30c10858dd6953341bff8e Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 19 Nov 2024 17:38:37 +0100 Subject: [PATCH 2/2] update var name --- src/presets/node/preset.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/presets/node/preset.ts b/src/presets/node/preset.ts index 8573733ddb..0b946f05cb 100644 --- a/src/presets/node/preset.ts +++ b/src/presets/node/preset.ts @@ -36,11 +36,11 @@ const nodeCluster = defineNitroPreset( "rollup:before"(_nitro, rollupConfig) { const manualChunks = rollupConfig.output?.manualChunks; if (manualChunks && typeof manualChunks === "function") { - const clusterEntry = resolvePathSync("./runtime/node-server", { + const serverEntry = resolvePathSync("./runtime/node-server", { url: import.meta.url, }); rollupConfig.output.manualChunks = (id, meta) => { - if (id.includes("node-server") && normalize(id) === clusterEntry) { + if (id.includes("node-server") && normalize(id) === serverEntry) { return "nitro/node-worker"; } return manualChunks(id, meta);