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

Rename confusing loaders #59827

Merged
merged 2 commits into from
Dec 20, 2023
Merged
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
24 changes: 12 additions & 12 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ export default async function getBaseWebpackConfig(
babel: useSWCLoader ? swcDefaultLoader : babelLoader!,
}

const swcLoaderForServerLayer = hasAppDir
const appServerLayerLoaders = hasAppDir
? [
// When using Babel, we will have to add the SWC loader
// as an additional pass to handle RSC correctly.
Expand All @@ -479,7 +479,7 @@ export default async function getBaseWebpackConfig(
].filter(Boolean)
: []

const swcLoaderForMiddlewareLayer = [
const middlewareLayerLoaders = [
// When using Babel, we will have to use SWC to do the optimization
// for middleware to tree shake the unused default optimized imports like "next/server".
// This will cause some performance overhead but
Expand All @@ -495,7 +495,7 @@ export default async function getBaseWebpackConfig(
dev && isClient ? [require.resolve(reactRefreshLoaderName)] : []

// client components layers: SSR or browser
const createSwcLoaderForClientLayer = ({
const createClientLayerLoader = ({
isBrowserLayer,
reactRefresh,
}: {
Expand All @@ -520,20 +520,20 @@ export default async function getBaseWebpackConfig(
: []),
]

const swcLoaderForBrowserLayer = createSwcLoaderForClientLayer({
const appBrowserLayerLoaders = createClientLayerLoader({
isBrowserLayer: true,
// reactRefresh for browser layer is applied conditionally to user-land source
reactRefresh: false,
})
const swcLoaderForSSRLayer = createSwcLoaderForClientLayer({
const appSSRLayerLoaders = createClientLayerLoader({
isBrowserLayer: false,
reactRefresh: true,
})

// Loader for API routes needs to be differently configured as it shouldn't
// have RSC transpiler enabled, so syntax checks such as invalid imports won't
// be performed.
const loaderForAPIRoutes =
const apiRoutesLayerLoaders =
hasAppDir && useSWCLoader
? getSwcLoader({
serverComponents: false,
Expand Down Expand Up @@ -1415,40 +1415,40 @@ export default async function getBaseWebpackConfig(
// Switch back to normal URL handling
url: true,
},
use: loaderForAPIRoutes,
use: apiRoutesLayerLoaders,
},
{
test: codeCondition.test,
issuerLayer: WEBPACK_LAYERS.middleware,
use: swcLoaderForMiddlewareLayer,
use: middlewareLayerLoaders,
},
...(hasAppDir
? [
{
test: codeCondition.test,
issuerLayer: isWebpackServerLayer,
exclude: asyncStoragesRegex,
use: swcLoaderForServerLayer,
use: appServerLayerLoaders,
},
{
test: codeCondition.test,
resourceQuery: new RegExp(
WEBPACK_RESOURCE_QUERIES.edgeSSREntry
),
use: swcLoaderForServerLayer,
use: appServerLayerLoaders,
},
{
test: codeCondition.test,
issuerLayer: WEBPACK_LAYERS.appPagesBrowser,
use: swcLoaderForBrowserLayer,
use: appBrowserLayerLoaders,
resolve: {
mainFields: getMainField(compilerType, true),
},
},
{
test: codeCondition.test,
issuerLayer: WEBPACK_LAYERS.serverSideRendering,
use: swcLoaderForSSRLayer,
use: appSSRLayerLoaders,
resolve: {
mainFields: getMainField(compilerType, true),
},
Expand Down