diff --git a/src/presets/node/preset.ts b/src/presets/node/preset.ts index b2cc1d346c..0b946f05cb 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 serverEntry = resolvePathSync("./runtime/node-server", { + url: import.meta.url, + }); + rollupConfig.output.manualChunks = (id, meta) => { + if (id.includes("node-server") && normalize(id) === serverEntry) { + return "nitro/node-worker"; + } + return manualChunks(id, meta); + }; + } + }, + }, }, { name: "node-cluster" as const,