@@ -50,15 +50,12 @@ export async function bundleServer(buildOpts: BuildOptions, projectOpts: Project
5050 copyPackageCliFiles ( packageDistDir , buildOpts ) ;
5151
5252 const { appPath, outputDir, monorepoRoot, debug } = buildOpts ;
53- const baseManifestPath = path . join (
54- outputDir ,
55- "server-functions/default" ,
56- getPackagePath ( buildOpts ) ,
57- ".next"
58- ) ;
59- const serverFiles = path . join ( baseManifestPath , "required-server-files.json" ) ;
53+ const dotNextPath = path . join ( outputDir , "server-functions/default" , getPackagePath ( buildOpts ) , ".next" ) ;
54+ const serverFiles = path . join ( dotNextPath , "required-server-files.json" ) ;
6055 const nextConfig = JSON . parse ( fs . readFileSync ( serverFiles , "utf-8" ) ) . config ;
6156
57+ const useTurbopack = fs . existsSync ( path . join ( dotNextPath , "server/chunks/[turbopack]_runtime.js" ) ) ;
58+
6259 console . log ( `\x1b[35m⚙️ Bundling the OpenNext server...\n\x1b[0m` ) ;
6360
6461 await patchWebpackRuntime ( buildOpts ) ;
@@ -141,6 +138,9 @@ export async function bundleServer(buildOpts: BuildOptions, projectOpts: Project
141138 // Note: we need the __non_webpack_require__ variable declared as it is used by next-server:
142139 // https://github.com/vercel/next.js/blob/be0c3283/packages/next/src/server/next-server.ts#L116-L119
143140 __non_webpack_require__ : "require" ,
141+ // The 2 following defines are used to reduce the bundle size by removing unnecessary code
142+ // Next uses different precompiled renderers (i.e. `app-page.runtime.prod.js`) based on if you use `TURBOPACK` or some experimental React features
143+ ...( useTurbopack ? { } : { "process.env.TURBOPACK" : "false" } ) ,
144144 // We make sure that environment variables that Next.js expects are properly defined
145145 "process.env.NEXT_RUNTIME" : '"nodejs"' ,
146146 "process.env.NODE_ENV" : '"production"' ,
0 commit comments