Skip to content

Commit

Permalink
fix(node-cluster): create dedicated chunk for worker (#2894)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Nov 19, 2024
1 parent 9563e9a commit 612da35
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/presets/node/preset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { defineNitroPreset } from "nitropack/kit";
import { normalize } from "pathe";
import { resolvePathSync } from "mlly";

const node = defineNitroPreset(
{
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 612da35

Please sign in to comment.