Skip to content

Commit

Permalink
avoid bundling in one file when middleware is inside server function
Browse files Browse the repository at this point in the history
  • Loading branch information
conico974 committed Sep 13, 2024
1 parent 69c71d3 commit 7c2277a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/open-next/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ async function createMiddleware() {
entrypoint: path.join(__dirname, "core", "edgeFunctionHandler.js"),
outfile: path.join(outputDir, ".build", "middleware.mjs"),
...commonMiddlewareOptions,
onlyBuildOnce: true,
});
}
}
32 changes: 18 additions & 14 deletions packages/open-next/src/build/edge/createEdgeBundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface BuildEdgeBundleOptions {
additionalInject?: string;
includeCache?: boolean;
additionalExternals?: string[];
onlyBuildOnce?: boolean;
}

export async function buildEdgeBundle({
Expand All @@ -45,6 +46,7 @@ export async function buildEdgeBundle({
additionalInject,
includeCache,
additionalExternals,
onlyBuildOnce,
}: BuildEdgeBundleOptions) {
const isInCloudfare =
typeof overrides?.wrapper === "string"
Expand Down Expand Up @@ -143,20 +145,22 @@ globalThis.AsyncLocalStorage = AsyncLocalStorage;
options,
);

await build({
entryPoints: [outfile],
outfile,
allowOverwrite: true,
bundle: true,
minify: true,
platform: "node",
format: "esm",
conditions: ["workerd", "worker", "browser"],
external: ["node:*", ...(additionalExternals ?? [])],
banner: {
js: 'import * as process from "node:process";',
},
});
if (!onlyBuildOnce) {
await build({
entryPoints: [outfile],
outfile,
allowOverwrite: true,
bundle: true,
minify: true,
platform: "node",
format: "esm",
conditions: ["workerd", "worker", "browser"],
external: ["node:*", ...(additionalExternals ?? [])],
banner: {
js: 'import * as process from "node:process";',
},
});
}
}

export function copyMiddlewareAssetsAndWasm({}) {}
Expand Down

0 comments on commit 7c2277a

Please sign in to comment.