Skip to content

Commit 0f67650

Browse files
committed
feat: cli arg to disable minification
1 parent 0d3b69d commit 0f67650

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

.changeset/nine-impalas-wave.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@opennextjs/cloudflare": minor
3+
---
4+
5+
feat: cli arg to disable minification
6+
7+
The cache handler currently forces minification. There is now a CLI arg to disable minification for the build. At the moment, this only applies to the cache handler but may be used for other parts of the build in the future when minification is introduced to them.

packages/cloudflare/src/cli/args.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { resolve } from "node:path";
55
export function getArgs(): {
66
skipBuild: boolean;
77
outputDir?: string;
8+
disableMinification?: boolean;
89
} {
910
const {
10-
values: { skipBuild, output },
11+
values: { skipBuild, output, disableMinification },
1112
} = parseArgs({
1213
options: {
1314
skipBuild: {
@@ -19,6 +20,9 @@ export function getArgs(): {
1920
type: "string",
2021
short: "o",
2122
},
23+
disableMinification: {
24+
type: "boolean",
25+
},
2226
},
2327
allowPositionals: false,
2428
});
@@ -32,6 +36,7 @@ export function getArgs(): {
3236
return {
3337
outputDir,
3438
skipBuild: skipBuild || ["1", "true", "yes"].includes(String(process.env.SKIP_NEXT_APP_BUILD)),
39+
disableMinification,
3540
};
3641
}
3742

packages/cloudflare/src/cli/build/patches/investigated/patch-cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function patchCache(code: string, config: Config): Promise<string>
1818
outfile: cacheHandlerOutputFile,
1919
format: "esm",
2020
target: "esnext",
21-
minify: true,
21+
minify: config.build.shouldMinify,
2222
define: {
2323
"process.env.__OPENNEXT_KV_BINDING_NAME": `"${config.cache.kvBindingName}"`,
2424
},

packages/cloudflare/src/cli/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export type Config = {
1616
timestamp: number;
1717
// Whether to skip building the Next.js app or not
1818
skipNextBuild: boolean;
19+
// Whether minification should be enabled or not
20+
shouldMinify: boolean;
1921
};
2022

2123
paths: {
@@ -69,6 +71,7 @@ export function getConfig(projectOpts: ProjectOptions): Config {
6971
build: {
7072
timestamp: Date.now(),
7173
skipNextBuild: !!projectOpts.skipBuild,
74+
shouldMinify: !projectOpts.disableMinification,
7275
},
7376

7477
paths: {
@@ -106,6 +109,8 @@ export type ProjectOptions = {
106109
outputDir: string;
107110
// Whether the Next.js build should be skipped (i.e. if the `.next` dir is already built)
108111
skipBuild?: boolean;
112+
// Whether minification of the worker should be disabled
113+
disableMinification?: boolean;
109114
};
110115

111116
/**

packages/cloudflare/src/cli/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ if (!["js", "cjs", "mjs", "ts"].some((ext) => existsSync(`./next.config.${ext}`)
1313
throw new Error("Error: Not in a Next.js app project");
1414
}
1515

16-
const { skipBuild, outputDir } = getArgs();
16+
const { skipBuild, outputDir, disableMinification } = getArgs();
1717

1818
await build({
1919
sourceDir: nextAppDir,
2020
outputDir: resolve(outputDir ?? nextAppDir, ".worker-next"),
2121
skipBuild,
22+
disableMinification,
2223
});

0 commit comments

Comments
 (0)