Unverified Commit 232dfbe8 authored by Shu Ding's avatar Shu Ding Committed by GitHub

Loader refactoring (#46304)

Similar to #46277, this refactors the loader code a bit and merged two loaders into one. 

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
parent ee7c0c5c
...@@ -1707,20 +1707,18 @@ export default async function getBaseWebpackConfig( ...@@ -1707,20 +1707,18 @@ export default async function getBaseWebpackConfig(
? [ ? [
{ {
issuerLayer: WEBPACK_LAYERS.server, issuerLayer: WEBPACK_LAYERS.server,
test: (req: string) => { test: {
// If it's not a source code file, or has been opted out of // Resolve it if it is a source code file, and it has NOT been
// bundling, don't resolve it. // opted out of bundling.
if ( and: [
!codeCondition.test.test(req) || codeCondition.test,
isResourceInPackages( {
req, not: [
config.experimental.serverComponentsExternalPackages optOutBundlingPackageRegex,
) staticGenerationAsyncStorageRegex,
) { ],
return false },
} ],
return true
}, },
resolve: { resolve: {
conditionNames: [ conditionNames: [
...@@ -1743,15 +1741,18 @@ export default async function getBaseWebpackConfig( ...@@ -1743,15 +1741,18 @@ export default async function getBaseWebpackConfig(
'next/dist/compiled/react-dom/server-rendering-stub', 'next/dist/compiled/react-dom/server-rendering-stub',
}, },
}, },
use: {
loader: 'next-flight-loader',
},
},
{
// Make sure that AsyncLocalStorage module instance is shared between server and client
// layers.
layer: WEBPACK_LAYERS.shared,
test: staticGenerationAsyncStorageRegex,
}, },
] ]
: []), : []),
...[
{
layer: WEBPACK_LAYERS.shared,
test: staticGenerationAsyncStorageRegex,
},
],
// TODO: FIXME: do NOT webpack 5 support with this // TODO: FIXME: do NOT webpack 5 support with this
// x-ref: https://github.com/webpack/webpack/issues/11467 // x-ref: https://github.com/webpack/webpack/issues/11467
...(!config.experimental.fullySpecified ...(!config.experimental.fullySpecified
...@@ -1775,19 +1776,6 @@ export default async function getBaseWebpackConfig( ...@@ -1775,19 +1776,6 @@ export default async function getBaseWebpackConfig(
}, },
] ]
: []), : []),
...(hasServerComponents && !isClient
? [
// RSC server compilation loaders
{
test: codeCondition.test,
exclude: [staticGenerationAsyncStorageRegex],
issuerLayer: WEBPACK_LAYERS.server,
use: {
loader: 'next-flight-loader',
},
},
]
: []),
...(hasServerComponents ...(hasServerComponents
? [ ? [
{ {
......
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