diff --git a/packages/next/src/build/webpack-config.ts b/packages/next/src/build/webpack-config.ts index b7bd3f408953e..6d55d0d8c4c8c 100644 --- a/packages/next/src/build/webpack-config.ts +++ b/packages/next/src/build/webpack-config.ts @@ -1188,7 +1188,7 @@ export default async function getBaseWebpackConfig( chunks: isRspack ? // using a function here causes noticable slowdown // in rspack - /(?!polyfills|main|pages\/_app)/ + /^(?!(polyfills|main|pages\/_app)$).*$/ : (chunk: any) => !/^(polyfills|main|pages\/_app)$/.test(chunk.name), @@ -1198,7 +1198,9 @@ export default async function getBaseWebpackConfig( chunks: 'all' as const, name: 'framework', layer: RSPACK_DEFAULT_LAYERS_REGEX, - test: /[/]node_modules[/](react|react-dom|next[/]dist[/]compiled[/](react|react-dom)(-experimental)?)[/]/, + test: new RegExp( + `^(${topLevelFrameworkPaths.map((p) => `(${escapeStringRegexp(p)})`).join('|')})` + ), priority: 40, enforce: true, },