Skip to content

Commit

Permalink
move opt-out check earlier in handle externals
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed May 7, 2024
1 parent 185a75c commit f00d931
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/next/src/build/handle-externals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,13 @@ export function makeExternalHandler({
return
}

const isOptOutBundling = optOutBundlingPackageRegex.test(res)
// Apply bundling rules to all app layers.
// Since handleExternals only handle the server layers, we don't need to exclude client here
if (!isOptOutBundling) {
return
}

// ESM externals can only be imported (and not required).
// Make an exception in loose mode.
if (!isEsmRequested && isEsm && !looseEsmExternals && !isLocal) {
Expand Down Expand Up @@ -421,14 +428,7 @@ function resolveBundlingOptOutPackages({
(!isAppLayer && config.experimental.bundlePagesExternals)

if (nodeModulesRegex.test(resolvedRes) || !resolvedRes.startsWith('.')) {
const isOptOutBundling = optOutBundlingPackageRegex.test(resolvedRes)
// Apply bundling rules to all app layers.
// Since handleExternals only handle the server layers, we don't need to exclude client here
if (isAppLayer) {
if (isOptOutBundling) {
return `${externalType} ${request}` // Externalize if opted out
}
} else if (!shouldBeBundled || isOptOutBundling) {
if (!isAppLayer && !shouldBeBundled) {
return `${externalType} ${request}` // Externalize if not bundled or opted out
}
}
Expand Down

0 comments on commit f00d931

Please sign in to comment.