Skip to content

Commit

Permalink
add missing client entry matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Jul 15, 2022
1 parent 27eb5bb commit 6e8a166
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
17 changes: 11 additions & 6 deletions packages/next/build/webpack/config/blocks/css/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const regexCssModules = /\.module\.css$/
// RegExps for Syntactically Awesome Style Sheets
const regexSassGlobal = /(?<!\.module)\.(scss|sass)$/
const regexSassModules = /\.module\.(scss|sass)$/
// Also match the virtual client entry which doesn't have file path
const clientEntryMatcher = (file: string) => !file

/**
* Mark a rule as removable if built-in CSS support is disabled
Expand Down Expand Up @@ -213,8 +215,13 @@ export const css = curry(async function css(
// CSS Modules are only supported in the user's application. We're
// not yet allowing CSS imports _within_ `node_modules`.
issuer: {
and: [ctx.rootDirectory],
not: [/node_modules/],
or: [
{
and: [ctx.rootDirectory],
not: [/node_modules/],
},
clientEntryMatcher,
],
},
use: getCssModuleLoader(ctx, lazyPostCSSInitializer),
}),
Expand Down Expand Up @@ -364,8 +371,7 @@ export const css = curry(async function css(
issuer: {
or: [
{ and: [ctx.rootDirectory, /\.(js|mjs|jsx|ts|tsx)$/] },
// Also match the virtual client entry which doesn't have file path
(filePath) => !filePath,
clientEntryMatcher,
],
},
use: getGlobalCssLoader(ctx, lazyPostCSSInitializer),
Expand All @@ -382,8 +388,7 @@ export const css = curry(async function css(
issuer: {
or: [
{ and: [ctx.rootDirectory, /\.(js|mjs|jsx|ts|tsx)$/] },
// Also match the virtual client entry which doesn't have file path
(filePath) => !filePath,
clientEntryMatcher,
],
},
use: getCssModuleLoader(ctx, lazyPostCSSInitializer),
Expand Down
10 changes: 5 additions & 5 deletions packages/next/build/webpack/plugins/client-entry-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ export class ClientEntryPlugin {
// client js: -> relative imports
// TODO-APP: applied loaders for css
// *.css (with loaders applied): -> relative css imports

const rawRequest = mod.rawRequest || ''
const { relativePath } = mod.resourceResolveData || {}
const modRequest =
mod.rawRequest &&
!mod.rawRequest.startsWith('.') &&
!mod.rawRequest.startsWith('/')
? mod.rawRequest
!rawRequest.endsWith('.css') &&
!rawRequest.startsWith('.') &&
!rawRequest.startsWith('/')
? rawRequest
: relativePath || mod.userRequest

if (visited.has(modRequest)) return
Expand Down

0 comments on commit 6e8a166

Please sign in to comment.