Skip to content

Commit

Permalink
fix(build): Do not minify OpenNext bundles (#144)
Browse files Browse the repository at this point in the history
This is required to apply string replacement patches.
Fixes #143
  • Loading branch information
vicb committed Dec 20, 2024
1 parent 031b5e0 commit 6dba7fc
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 31 deletions.
4 changes: 0 additions & 4 deletions packages/cloudflare/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ declare global {
OPEN_NEXT_ORIGIN: string;
}
}

interface Window {
[key: string]: string | Fetcher;
}
}

export {};
2 changes: 1 addition & 1 deletion packages/cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"vitest": "catalog:"
},
"dependencies": {
"@opennextjs/aws": "https://pkg.pr.new/@opennextjs/aws@2202f36",
"@opennextjs/aws": "https://pkg.pr.new/@opennextjs/aws@d2ead58",
"ts-morph": "catalog:"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cloudflare/src/cli/build/bundle-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export async function bundleServer(config: Config, openNextOptions: BuildOptions
// __dirname is used by unbundled js files (which don't inherit the __dirname present in the define field)
// so we also need to set it on the global scope
// Note: this was hit in the next/dist/compiled/@opentelemetry/api module
globalThis.__dirname ??= "";
// Do not crash on cache not supported
Expand Down Expand Up @@ -168,6 +167,7 @@ async function updateWorkerBundledCode(

patchedCode = patchedCode
// workers do not support dynamic require nor require.resolve
// TODO: implement for cf (possibly in @opennextjs/aws)
.replace("patchAsyncStorage();", "//patchAsyncStorage();")
.replace('require.resolve("./cache.cjs")', '"unused"');

Expand Down
4 changes: 4 additions & 0 deletions packages/cloudflare/src/cli/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export async function build(projectOpts: ProjectOptions): Promise<void> {
const options = buildHelper.normalizeOptions(config, openNextDistDir, buildDir);
logger.setLevel(options.debug ? "debug" : "info");

// Do not minify the code so that we can apply string replacement patch.
// Note that wrangler will still minify the bundle.
options.minify = false;

// Pre-build validation
buildHelper.checkRunningInsideNextjsApp(options);
logger.info(`App directory: ${options.appPath}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async function generateBundle(
const isBundled = fnOptions.experimentalBundledNextServer ?? false;
if (isBundled) {
await bundleNextServer(path.join(outputPath, packagePath), appPath, {
debug: options.debug,
minify: options.minify,
});
}

Expand Down
46 changes: 23 additions & 23 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ catalog:
"tsx": ^4.19.2
"typescript-eslint": ^8.7.0
"vitest": ^2.1.1
"wrangler": ^3.87.0
"wrangler": ^3.91.0

0 comments on commit 6dba7fc

Please sign in to comment.