Skip to content

Commit

Permalink
Simplify node/edge server chunking some
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Feb 23, 2024
1 parent ad48047 commit c081e59
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 c081e59

Please sign in to comment.