Skip to content

Commit

Permalink
Do not use webpack lazy imports for production
Browse files Browse the repository at this point in the history
  • Loading branch information
javivelasco committed Jan 25, 2024
1 parent a9c7559 commit c9269dc
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/next/src/build/webpack/loaders/next-app-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
}]`

Expand Down

0 comments on commit c9269dc

Please sign in to comment.