Skip to content

Commit

Permalink
Loader refactoring (#46304)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
shuding authored Feb 24, 2023
1 parent ee7c0c5 commit 232dfbe
Showing 1 changed file with 21 additions and 33 deletions.
54 changes: 21 additions & 33 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1707,20 +1707,18 @@ export default async function getBaseWebpackConfig(
? [
{
issuerLayer: WEBPACK_LAYERS.server,
test: (req: string) => {
// If it's not a source code file, or has been opted out of
// bundling, don't resolve it.
if (
!codeCondition.test.test(req) ||
isResourceInPackages(
req,
config.experimental.serverComponentsExternalPackages
)
) {
return false
}

return true
test: {
// Resolve it if it is a source code file, and it has NOT been
// opted out of bundling.
and: [
codeCondition.test,
{
not: [
optOutBundlingPackageRegex,
staticGenerationAsyncStorageRegex,
],
},
],
},
resolve: {
conditionNames: [
Expand All @@ -1743,15 +1741,18 @@ export default async function getBaseWebpackConfig(
'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
// x-ref: https://github.com/webpack/webpack/issues/11467
...(!config.experimental.fullySpecified
Expand All @@ -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
? [
{
Expand Down

0 comments on commit 232dfbe

Please sign in to comment.