Skip to content

Commit 6acf0fd

Browse files
authored
feat: cli arg to disable minification (#89)
* feat: cli arg to disable minification * rename disableMinification to noMinify * comment * tidy
1 parent 450efc7 commit 6acf0fd

File tree

6 files changed

+28
-9
lines changed

6 files changed

+28
-9
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. By default, minification is enabled, but can be disabled by passing `--noMinify`.

packages/cloudflare/src/cli/args.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import { parseArgs } from "node:util";
33
import { resolve } from "node:path";
44

55
export function getArgs(): {
6-
skipBuild: boolean;
6+
skipNextBuild: boolean;
77
outputDir?: string;
8+
minify: boolean;
89
} {
910
const {
10-
values: { skipBuild, output },
11+
values: { skipBuild, output, noMinify },
1112
} = parseArgs({
1213
options: {
1314
skipBuild: {
@@ -19,6 +20,10 @@ export function getArgs(): {
1920
type: "string",
2021
short: "o",
2122
},
23+
noMinify: {
24+
type: "boolean",
25+
default: false,
26+
},
2227
},
2328
allowPositionals: false,
2429
});
@@ -31,7 +36,8 @@ export function getArgs(): {
3136

3237
return {
3338
outputDir,
34-
skipBuild: skipBuild || ["1", "true", "yes"].includes(String(process.env.SKIP_NEXT_APP_BUILD)),
39+
skipNextBuild: skipBuild || ["1", "true", "yes"].includes(String(process.env.SKIP_NEXT_APP_BUILD)),
40+
minify: !noMinify,
3541
};
3642
}
3743

packages/cloudflare/src/cli/build/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { rm } from "node:fs/promises";
1414
* @param projectOpts The options for the project
1515
*/
1616
export async function build(projectOpts: ProjectOptions): Promise<void> {
17-
if (!projectOpts.skipBuild) {
17+
if (!projectOpts.skipNextBuild) {
1818
// Build the next app
1919
await buildNextjsApp(projectOpts.sourceDir);
2020
}

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: 7 additions & 2 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: {
@@ -63,7 +65,8 @@ export function getConfig(projectOpts: ProjectOptions): Config {
6365
return {
6466
build: {
6567
timestamp: Date.now(),
66-
skipNextBuild: !!projectOpts.skipBuild,
68+
skipNextBuild: projectOpts.skipNextBuild,
69+
shouldMinify: projectOpts.minify,
6770
},
6871

6972
paths: {
@@ -100,7 +103,9 @@ export type ProjectOptions = {
100103
// The directory to save the output to (defaults to the app's directory)
101104
outputDir: string;
102105
// Whether the Next.js build should be skipped (i.e. if the `.next` dir is already built)
103-
skipBuild?: boolean;
106+
skipNextBuild: boolean;
107+
// Whether minification of the worker should be enabled
108+
minify: boolean;
104109
};
105110

106111
/**

packages/cloudflare/src/cli/index.ts

Lines changed: 3 additions & 2 deletions
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 { skipNextBuild, outputDir, minify } = getArgs();
2020

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

0 commit comments

Comments
 (0)