Skip to content

Commit

Permalink
fix: make sure nitro runtime goes to one chunk (#2547)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Jun 19, 2024
1 parent a99680e commit 8b4a408
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/rollup/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,25 @@ export const getRollupConfig = (nitro: Nitro): RollupConfig => {

const buildServerDir = join(nitro.options.buildDir, "dist/server");

const presetsDir = resolve(runtimeDir, "../presets");

const chunkNamePrefixes = [
[nitro.options.buildDir, "build"],
[buildServerDir, "app"],
[runtimeDir, "nitro"],
[presetsDir, "nitro"],
["\0raw:", "raw"],
["\0nitro-wasm:", "wasm"],
["\0", "virtual"],
] as const;
function getChunkName(id: string) {
// Runtime
if (id.startsWith(runtimeDir)) {
return `chunks/runtime.mjs`;

function getChunkGroup(id: string): string | void {
if (id.startsWith(runtimeDir) || id.startsWith(presetsDir)) {
return "nitro";
}
}

function getChunkName(id: string) {
// Known path prefixes
for (const [dir, name] of chunkNamePrefixes) {
if (id.startsWith(dir)) {
Expand Down Expand Up @@ -131,6 +137,9 @@ export const getRollupConfig = (nitro: Nitro): RollupConfig => {
const lastModule = normalize(chunk.moduleIds.at(-1) || "");
return getChunkName(lastModule);
},
manualChunks(id) {
return getChunkGroup(id);
},
inlineDynamicImports: nitro.options.inlineDynamicImports,
format: "esm",
exports: "auto",
Expand Down Expand Up @@ -177,6 +186,10 @@ export const getRollupConfig = (nitro: Nitro): RollupConfig => {
},
});

if (rollupConfig.output.inlineDynamicImports) {
delete rollupConfig.output.manualChunks;
}

if (nitro.options.timing) {
rollupConfig.plugins.push(timing());
}
Expand Down

0 comments on commit 8b4a408

Please sign in to comment.