From c9269dcf257624748746577e9bad61de39eb0e68 Mon Sep 17 00:00:00 2001 From: Javi Velasco Date: Thu, 25 Jan 2024 10:19:35 +0100 Subject: [PATCH] Do not use webpack lazy imports for production --- .../next/src/build/webpack/loaders/next-app-loader.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/next/src/build/webpack/loaders/next-app-loader.ts b/packages/next/src/build/webpack/loaders/next-app-loader.ts index 5fdae7e86751f8..c4474c6ee2e429 100644 --- a/packages/next/src/build/webpack/loaders/next-app-loader.ts +++ b/packages/next/src/build/webpack/loaders/next-app-loader.ts @@ -280,13 +280,17 @@ async function createTreeCodeFromPath( const resolvedPagePath = await resolver(matchedPagePath) if (resolvedPagePath) pages.push(resolvedPagePath) + const pathStr = JSON.stringify(resolvedPagePath) + const importStatement = + process.env.NODE_ENV !== 'production' + ? `[() => import(/* webpackMode: "eager" */ ${pathStr}), ${pathStr}]` + : `import(${pathStr})` + // Use '' for segment as it's the page. There can't be a segment called '' so this is the safest way to add it. props[ normalizeParallelKey(parallelKey) ] = `['${PAGE_SEGMENT_KEY}', {}, { - page: [() => import(/* webpackMode: "eager" */ ${JSON.stringify( - resolvedPagePath - )}), ${JSON.stringify(resolvedPagePath)}], + page: ${importStatement}, ${createMetadataExportsCode(metadata)} }]`