Skip to content

Commit 0ad33df

Browse files
committed
feat: cli arg to disable minification
1 parent 450efc7 commit 0ad33df

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
@@ -26,7 +26,7 @@ export async function patchCache(code: string, config: Config): Promise<string>
2626
outfile: cacheHandlerOutputFile,
2727
format: "esm",
2828
target: "esnext",
29-
minify: true,
29+
minify: config.build.shouldMinify,
3030
define: {
3131
"process.env.__OPENNEXT_KV_BINDING_NAME": `"${config.cache.kvBindingName}"`,
3232
},

packages/cloudflare/src/cli/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export type Config = {
99
timestamp: number;
1010
// Whether to skip building the Next.js app or not
1111
skipNextBuild: boolean;
12+
// Whether minification should be enabled or not
13+
shouldMinify: boolean;
1214
};
1315

1416
paths: {
@@ -64,6 +66,7 @@ export function getConfig(projectOpts: ProjectOptions): Config {
6466
build: {
6567
timestamp: Date.now(),
6668
skipNextBuild: !!projectOpts.skipBuild,
69+
shouldMinify: !projectOpts.disableMinification,
6770
},
6871

6972
paths: {
@@ -101,6 +104,8 @@ export type ProjectOptions = {
101104
outputDir: string;
102105
// Whether the Next.js build should be skipped (i.e. if the `.next` dir is already built)
103106
skipBuild?: boolean;
107+
// Whether minification of the worker should be disabled
108+
disableMinification?: boolean;
104109
};
105110

106111
/**

packages/cloudflare/src/cli/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ if (!["js", "cjs", "mjs", "ts"].some((ext) => existsSync(`./next.config.${ext}`)
1616
process.exit(1);
1717
}
1818

19-
const { skipBuild, outputDir } = getArgs();
19+
const { skipBuild, outputDir, disableMinification } = getArgs();
2020

2121
await build({
2222
sourceDir: nextAppDir,
2323
outputDir: resolve(outputDir ?? nextAppDir, ".worker-next"),
2424
skipBuild,
25+
disableMinification,
2526
});

0 commit comments

Comments
 (0)