Skip to content

Commit

Permalink
switch to module rules
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding committed Sep 23, 2022
1 parent 366aa79 commit c2253ba
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 50 deletions.
26 changes: 26 additions & 0 deletions packages/next/build/webpack-config.ts
Expand Up @@ -1490,6 +1490,32 @@ export default async function getBaseWebpackConfig(
},
module: {
rules: [
...(config.experimental.appDir && !isClient && !isEdgeServer
? [
{
issuerLayer: WEBPACK_LAYERS.server,
resolve: process.env.__NEXT_REACT_CHANNEL
? {
conditionNames: ['react-server'],
alias: {
react: `react-${process.env.__NEXT_REACT_CHANNEL}`,
'react-dom': `react-dom-${process.env.__NEXT_REACT_CHANNEL}`,
},
}
: {
conditionNames: ['react-server'],
alias: {
// If missing the alias override here, the default alias will be used which aliases
// react to the direct file path, not the package name. In that case the condition
// will be ignored completely.
react: 'react',
'react-dom': 'react-dom',
},
},
},
]
: []),

// TODO: FIXME: do NOT webpack 5 support with this
// x-ref: https://github.com/webpack/webpack/issues/11467
...(!config.experimental.fullySpecified
Expand Down
Expand Up @@ -11,14 +11,7 @@ import type {
ClientComponentImports,
NextFlightClientEntryLoaderOptions,
} from '../loaders/next-flight-client-entry-loader'
import {
APP_DIR_ALIAS,
DOT_NEXT_ALIAS,
PAGES_DIR_ALIAS,
ROOT_DIR_ALIAS,
RSC_MOD_REF_PROXY_ALIAS,
WEBPACK_LAYERS,
} from '../../../lib/constants'
import { APP_DIR_ALIAS } from '../../../lib/constants'
import {
COMPILER_NAMES,
FLIGHT_SERVER_CSS_MANIFEST,
Expand Down Expand Up @@ -62,47 +55,6 @@ export class FlightClientEntryPlugin {
(webpack as any).dependencies.ModuleDependency,
new (webpack as any).dependencies.NullDependency.Template()
)

normalModuleFactory.hooks.resolve.tap(
PLUGIN_NAME,
function (resolveData: any) {
if (
resolveData.contextInfo.issuerLayer === WEBPACK_LAYERS.server &&
// TODO-APP: Handle edge-server here correctly.
resolveData.contextInfo.compiler === 'server'
) {
if (
[
PAGES_DIR_ALIAS,
ROOT_DIR_ALIAS,
DOT_NEXT_ALIAS,
APP_DIR_ALIAS,
RSC_MOD_REF_PROXY_ALIAS,
].some((alias) => resolveData.request.startsWith(alias))
) {
return
}

resolveData.resolveOptions = {
...resolveData.resolveOptions,
conditionNames: ['react-server'],
alias: process.env.__NEXT_REACT_CHANNEL
? {
react: `react-${process.env.__NEXT_REACT_CHANNEL}`,
'react/package.json': `react-${process.env.__NEXT_REACT_CHANNEL}/package.json`,
'react/jsx-runtime': `react-${process.env.__NEXT_REACT_CHANNEL}/jsx-runtime`,
'react/jsx-dev-runtime': `react-${process.env.__NEXT_REACT_CHANNEL}/jsx-dev-runtime`,
'react-dom': `react-dom-${process.env.__NEXT_REACT_CHANNEL}`,
'react-dom/package.json': `react-dom-${process.env.__NEXT_REACT_CHANNEL}/package.json`,
'react-dom/server': `react-dom-${process.env.__NEXT_REACT_CHANNEL}/server`,
'react-dom/server.browser': `react-dom-${process.env.__NEXT_REACT_CHANNEL}/server.browser`,
'react-dom/client': `react-dom-${process.env.__NEXT_REACT_CHANNEL}/client`,
}
: false,
}
}
}
)
}
)

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/app-dir/rsc-basic.test.ts
Expand Up @@ -406,7 +406,7 @@ describe('app dir - react server components', () => {
})
})

it.only('should resolve 3rd party package exports based on the react-server condition', async () => {
it('should resolve 3rd party package exports based on the react-server condition', async () => {
await fetchViaHTTP(next.url, '/react-server/3rd-party-package').then(
async (response) => {
const result = await resolveStreamResponse(response)
Expand Down

0 comments on commit c2253ba

Please sign in to comment.