Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix external logic #56302

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

# Tooling & Telemetry

/packages/next/src/build/ @timneutkens @ijjk @shuding @huozhi @ztanner @vercel/web-tooling
/packages/next/src/build/ @timneutkens @ijjk @shuding @huozhi @ztanner @feedthejim @vercel/web-tooling
/packages/next/src/server/lib/router-utils/setup-dev.ts @timneutkens @ijjk @shuding @huozhi @feedthejim @ztanner @wyattjoh @vercel/web-tooling
/packages/next/src/telemetry/ @timneutkens @ijjk @shuding @padmaia
/packages/next-swc/ @timneutkens @ijjk @shuding @huozhi @vercel/web-tooling
Expand Down
30 changes: 7 additions & 23 deletions packages/next/src/build/handle-externals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,8 @@ export function makeExternalHandler({
return resolveResult.localRes
}

// Forcedly resolve the styled-jsx installed by next.js,
// since `resolveExternal` cannot find the styled-jsx dep with pnpm
if (request === 'styled-jsx/style') {
resolveResult.res = defaultOverrides['styled-jsx/style']
if (request === 'styled-jsx/style' && !isAppLayer) {
return `commonjs ${defaultOverrides['styled-jsx/style']}`
}

const { res, isEsm } = resolveResult
Expand Down Expand Up @@ -372,30 +370,16 @@ export function makeExternalHandler({
config.transpilePackages,
resolvedExternalPackageDirs
) ||
(isEsm && isAppLayer) ||
isAppLayer ||
(!isAppLayer && config.experimental.bundlePagesExternals)

if (/node_modules[/\\].*\.[mc]?js$/.test(res)) {
if (isWebpackServerLayer(layer)) {
// All packages should be bundled for the server layer if they're not opted out.
// This option takes priority over the transpilePackages option.

if (optOutBundlingPackageRegex.test(res)) {
return `${externalType} ${request}`
}

return
}

if (shouldBeBundled) return

// Anything else that is standard JavaScript within `node_modules`
// can be externalized.
if (
/node_modules[/\\].*\.[mc]?js$/.test(res) &&
(optOutBundlingPackageRegex.test(res) || !shouldBeBundled)
) {
return `${externalType} ${request}`
}

if (shouldBeBundled) return

// Default behavior: bundle the code!
}
}
Loading