Skip to content

Commit cdcaa97

Browse files
authored
feat(build): add BuildOptions#minify to enable code minification (#655)
1 parent 80b24f7 commit cdcaa97

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

packages/open-next/src/build/bundleNextServer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const externals = [
4545
export async function bundleNextServer(
4646
outputDir: string,
4747
appPath: string,
48-
{ debug = false },
48+
{ minify = true },
4949
) {
5050
const require = createRequire(`${appPath}/package.json`);
5151
const entrypoint = require.resolve("next/dist/esm/server/next-server.js");
@@ -58,7 +58,7 @@ export async function bundleNextServer(
5858
// packages: "external",
5959
format: "cjs",
6060
external: externals,
61-
minify: !debug,
61+
minify,
6262
outfile: path.join(outputDir, "next-server.runtime.prod.js"),
6363
sourcemap: false,
6464
plugins: [

packages/open-next/src/build/createServerBundle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ async function generateBundle(
134134
const isBundled = fnOptions.experimentalBundledNextServer ?? false;
135135
if (isBundled) {
136136
await bundleNextServer(path.join(outputPath, packagePath), appPath, {
137-
debug: options.debug,
137+
minify: options.minify,
138138
});
139139
}
140140

packages/open-next/src/build/edge/createEdgeBundle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ globalThis.AsyncLocalStorage = AsyncLocalStorage;
160160
outfile,
161161
allowOverwrite: true,
162162
bundle: true,
163-
minify: !options.debug,
163+
minify: options.minify,
164164
platform: "node",
165165
format: "esm",
166166
conditions: ["workerd", "worker", "browser"],

packages/open-next/src/build/helper.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,18 @@ export function normalizeOptions(
4343
appPackageJsonPath = findNextPackageJsonPath(appPath, monorepoRoot);
4444
}
4545

46+
const debug = Boolean(process.env.OPEN_NEXT_DEBUG) ?? false;
47+
4648
return {
4749
appBuildOutputPath: buildOutputPath,
4850
appPackageJsonPath,
4951
appPath,
5052
appPublicPath: path.join(appPath, "public"),
5153
buildDir: path.join(outputDir, ".build"),
5254
config,
53-
debug: Boolean(process.env.OPEN_NEXT_DEBUG) ?? false,
55+
debug,
56+
// Whether ESBuild should minify the code
57+
minify: !debug,
5458
monorepoRoot,
5559
nextVersion: getNextVersion(appPath),
5660
openNextVersion: getOpenNextVersion(),
@@ -98,13 +102,13 @@ export function esbuildSync(
98102
esbuildOptions: ESBuildOptions,
99103
options: BuildOptions,
100104
) {
101-
const { openNextVersion, debug } = options;
105+
const { openNextVersion, debug, minify } = options;
102106
const result = buildSync({
103107
target: "esnext",
104108
format: "esm",
105109
platform: "node",
106110
bundle: true,
107-
minify: !debug,
111+
minify,
108112
mainFields: ["module", "main"],
109113
sourcemap: debug ? "inline" : false,
110114
sourcesContent: false,
@@ -134,13 +138,13 @@ export async function esbuildAsync(
134138
esbuildOptions: ESBuildOptions,
135139
options: BuildOptions,
136140
) {
137-
const { openNextVersion, debug } = options;
141+
const { openNextVersion, debug, minify } = options;
138142
const result = await buildAsync({
139143
target: "esnext",
140144
format: "esm",
141145
platform: "node",
142146
bundle: true,
143-
minify: !debug,
147+
minify,
144148
mainFields: ["module", "main"],
145149
sourcemap: debug ? "inline" : false,
146150
sourcesContent: false,

0 commit comments

Comments
 (0)