Skip to content

Commit bb5fd4a

Browse files
committed
feat: cli arg to disable minification
1 parent cc44647 commit bb5fd4a

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
shouldSkip: boolean;
19+
// Whether to disable minification or not
20+
shouldMinify: boolean;
1921
};
2022

2123
paths: {
@@ -53,6 +55,7 @@ export type Config = {
5355
* @param opts.sourceDir Next app root folder
5456
* @param opts.outputDir The directory where to save the output (defaults to the app's directory)
5557
* @param opts.skipBuild Whether the Next.js build should be skipped (i.e. if the `.next` dir is already built)
58+
* @param opts.disableMinification Whether minification of the worker should be disabled
5659
*
5760
* @returns The configuration, see `Config`
5861
*/
@@ -72,6 +75,7 @@ export function getConfig(opts: ProjectOptions): Config {
7275
build: {
7376
timestamp: Date.now(),
7477
shouldSkip: !!opts.skipBuild,
78+
shouldMinify: !opts.disableMinification,
7579
},
7680

7781
paths: {
@@ -106,6 +110,7 @@ export type ProjectOptions = {
106110
sourceDir: string;
107111
outputDir: string;
108112
skipBuild?: boolean;
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)