Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/nine-impalas-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@opennextjs/cloudflare": minor
---

feat: cli arg to disable minification

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.
7 changes: 6 additions & 1 deletion packages/cloudflare/src/cli/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { resolve } from "node:path";
export function getArgs(): {
skipBuild: boolean;
outputDir?: string;
disableMinification?: boolean;
} {
const {
values: { skipBuild, output },
values: { skipBuild, output, disableMinification },
} = parseArgs({
options: {
skipBuild: {
Expand All @@ -19,6 +20,9 @@ export function getArgs(): {
type: "string",
short: "o",
},
disableMinification: {
type: "boolean",
},
},
allowPositionals: false,
});
Expand All @@ -32,6 +36,7 @@ export function getArgs(): {
return {
outputDir,
skipBuild: skipBuild || ["1", "true", "yes"].includes(String(process.env.SKIP_NEXT_APP_BUILD)),
disableMinification,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function patchCache(code: string, config: Config): Promise<string>
outfile: cacheHandlerOutputFile,
format: "esm",
target: "esnext",
minify: true,
minify: config.build.shouldMinify,
define: {
"process.env.__OPENNEXT_KV_BINDING_NAME": `"${config.cache.kvBindingName}"`,
},
Expand Down
5 changes: 5 additions & 0 deletions packages/cloudflare/src/cli/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export type Config = {
timestamp: number;
// Whether to skip building the Next.js app or not
skipNextBuild: boolean;
// Whether minification should be enabled or not
shouldMinify: boolean;
};

paths: {
Expand Down Expand Up @@ -64,6 +66,7 @@ export function getConfig(projectOpts: ProjectOptions): Config {
build: {
timestamp: Date.now(),
skipNextBuild: !!projectOpts.skipBuild,
shouldMinify: !projectOpts.disableMinification,
},

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

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/cloudflare/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ if (!["js", "cjs", "mjs", "ts"].some((ext) => existsSync(`./next.config.${ext}`)
process.exit(1);
}

const { skipBuild, outputDir } = getArgs();
const { skipBuild, outputDir, disableMinification } = getArgs();

await build({
sourceDir: nextAppDir,
outputDir: resolve(outputDir ?? nextAppDir, ".worker-next"),
skipBuild,
disableMinification,
});