Skip to content

Commit

Permalink
Simplify node/edge server chunking some (#62424)
Browse files Browse the repository at this point in the history
This continues #62336 and ensures
we chunk fully but removes the cache groups as that introduces some
un-necessary duplication. With this configuration we ensure we split
chunks of all types which fixes the OOM/cache size issue and also avoids
overall chunk size increase.

Closes NEXT-2577
  • Loading branch information
ijjk committed Feb 23, 2024
1 parent 749e3c4 commit dfaa9ef
Showing 1 changed file with 8 additions and 28 deletions.
36 changes: 8 additions & 28 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,14 @@ export default async function getBaseWebpackConfig(
return false
}

if (isNodeServer || isEdgeServer) {
return {
filename: `${isEdgeServer ? 'edge-chunks/' : ''}[name].js`,
chunks: 'all',
minChunks: 2,
}
}

const frameworkCacheGroup = {
chunks: 'all' as const,
name: 'framework',
Expand All @@ -988,21 +996,6 @@ export default async function getBaseWebpackConfig(
enforce: true,
}

const nextRuntimeCacheGroup = {
chunks: 'all' as const,
name: 'next-runtime',
test(module: any) {
const resource = module.nameForCondition?.()
return resource
? nextFrameworkPaths.some((pkgPath) =>
resource.startsWith(pkgPath)
)
: false
},
priority: 30,
enforce: true,
}

const libCacheGroup = {
test(module: {
size: Function
Expand Down Expand Up @@ -1045,19 +1038,6 @@ export default async function getBaseWebpackConfig(
reuseExistingChunk: true,
}

if (isNodeServer || isEdgeServer) {
return {
filename: `${isEdgeServer ? 'edge-chunks/' : ''}[name].js`,
cacheGroups: {
nextRuntime: nextRuntimeCacheGroup,
framework: frameworkCacheGroup,
lib: libCacheGroup,
},
chunks: 'all',
minChunks: 2,
}
}

// client chunking
const cssCacheGroup = {
test: /\.(css|sass|scss)$/i,
Expand Down

0 comments on commit dfaa9ef

Please sign in to comment.