Commit 0c85bd01 authored by Tim Neutkens's avatar Tim Neutkens

Merge branch 'canary' of github.com:vercel/next.js into canary

parents a78ce92e b806985f
...@@ -124,6 +124,12 @@ function errorIfEnvConflicted(config: NextConfigComplete, key: string) { ...@@ -124,6 +124,12 @@ function errorIfEnvConflicted(config: NextConfigComplete, key: string) {
} }
} }
function isResourceInPackages(resource: string, packageNames?: string[]) {
return packageNames?.some((p: string) =>
new RegExp('[/\\\\]node_modules[/\\\\]' + p + '[/\\\\]').test(resource)
)
}
export function getDefineEnv({ export function getDefineEnv({
dev, dev,
config, config,
...@@ -1137,8 +1143,9 @@ export default async function getBaseWebpackConfig( ...@@ -1137,8 +1143,9 @@ export default async function getBaseWebpackConfig(
if (layer === WEBPACK_LAYERS.server) { if (layer === WEBPACK_LAYERS.server) {
// All packages should be bundled for the server layer if they're not opted out. // All packages should be bundled for the server layer if they're not opted out.
if ( if (
config.experimental.optoutServerComponentsBundle?.some((p: string) => isResourceInPackages(
new RegExp('node_modules[/\\\\]' + p + '[/\\\\]').test(res) res,
config.experimental.serverComponentsExternalPackages
) )
) { ) {
return `${externalType} ${request}` return `${externalType} ${request}`
...@@ -1514,16 +1521,18 @@ export default async function getBaseWebpackConfig( ...@@ -1514,16 +1521,18 @@ export default async function getBaseWebpackConfig(
{ {
issuerLayer: WEBPACK_LAYERS.server, issuerLayer: WEBPACK_LAYERS.server,
test: (req: string) => { test: (req: string) => {
// If it's not a source code file, or has been opted out of
// bundling, don't resolve it.
if ( if (
!codeCondition.test.test(req) || !codeCondition.test.test(req) ||
config.experimental.optoutServerComponentsBundle?.some( isResourceInPackages(
(mod) => { req,
return req.includes('/node_modules/' + mod + '/') config.experimental.serverComponentsExternalPackages
}
) )
) { ) {
return false return false
} }
return true return true
}, },
resolve: process.env.__NEXT_REACT_CHANNEL resolve: process.env.__NEXT_REACT_CHANNEL
......
...@@ -323,7 +323,7 @@ const configSchema = { ...@@ -323,7 +323,7 @@ const configSchema = {
optimisticClientCache: { optimisticClientCache: {
type: 'boolean', type: 'boolean',
}, },
optoutServerComponentsBundle: { serverComponentsExternalPackages: {
items: { items: {
type: 'string', type: 'string',
}, },
......
...@@ -154,7 +154,7 @@ export interface ExperimentalConfig { ...@@ -154,7 +154,7 @@ export interface ExperimentalConfig {
adjustFontFallbacksWithSizeAdjust?: boolean adjustFontFallbacksWithSizeAdjust?: boolean
// A list of packages that should be treated as external in the RSC server build // A list of packages that should be treated as external in the RSC server build
optoutServerComponentsBundle?: string[] serverComponentsExternalPackages?: string[]
fontLoaders?: { [fontLoader: string]: any } fontLoaders?: { [fontLoader: string]: any }
} }
......
...@@ -5,7 +5,7 @@ module.exports = { ...@@ -5,7 +5,7 @@ module.exports = {
}, },
experimental: { experimental: {
appDir: true, appDir: true,
optoutServerComponentsBundle: ['conditional-exports-optout'], serverComponentsExternalPackages: ['conditional-exports-optout'],
}, },
rewrites: async () => { rewrites: async () => {
return { return {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment