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

Fix app dir vanilla-extract support #48306

Merged
merged 2 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions packages/next/src/build/webpack/loaders/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@ export function isClientComponentModule(mod: {

export const regexCSS = /\.(css|scss|sass)(\?.*)?$/

// This function checks if a module is able to emit CSS resources. You should
// never only rely on a single regex to do that.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be made extensible for more tools?

export function isCSSMod(mod: {
resource: string
type?: string
loaders?: { loader: string }[]
}): boolean {
return !!(
mod.type === 'css/mini-extract' ||
(mod.resource && regexCSS.test(mod.resource)) ||
mod.loaders?.some(
({ loader }) =>
loader.includes('next-style-loader/index.js') ||
loader.includes('mini-css-extract-plugin/loader.js') ||
loader.includes('@vanilla-extract/webpack-plugin/loader/')
)
)
}

export function getActions(mod: {
resource: string
buildInfo: any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
generateActionId,
getActions,
isClientComponentModule,
regexCSS,
isCSSMod,
} from '../loaders/utils'
import { traverseModules, forEachEntryModule } from '../utils'
import { normalizePathSep } from '../../../shared/lib/page-path/normalize-path-sep'
Expand Down Expand Up @@ -354,7 +354,7 @@ export class ClientReferenceEntryPlugin {
const resource = mod.resource
const modId = resource
if (modId) {
if (regexCSS.test(modId)) {
if (isCSSMod(mod)) {
cssImportsForChunk[entryName].add(modId)
}
}
Expand Down Expand Up @@ -506,8 +506,7 @@ export class ClientReferenceEntryPlugin {
compilation.moduleGraph.getResolvedModule(dependencyToFilter)
if (!mod) return

const rawRequest = mod.rawRequest
const isCSS = regexCSS.test(rawRequest)
const isCSS = isCSSMod(mod)

// We have to always use the resolved request here to make sure the
// server and client are using the same module path (required by RSC), as
Expand Down
14 changes: 2 additions & 12 deletions packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
SYSTEM_ENTRYPOINTS,
} from '../../../shared/lib/constants'
import { relative, sep } from 'path'
import { isClientComponentModule, regexCSS } from '../loaders/utils'
import { isClientComponentModule, isCSSMod } from '../loaders/utils'
import { getProxiedPluginState } from '../../build-context'

import { traverseModules } from '../utils'
Expand Down Expand Up @@ -157,17 +157,7 @@ export class ClientReferenceManifestPlugin {
mod: webpack.NormalModule,
chunkCSS: string[]
) => {
const isCSSModule =
regexCSS.test(mod.resource) ||
mod.type === 'css/mini-extract' ||
(!!mod.loaders &&
(dev
? mod.loaders.some((item) =>
item.loader.includes('next-style-loader/index.js')
)
: mod.loaders.some((item) =>
item.loader.includes('mini-css-extract-plugin/loader.js')
)))
const isCSSModule = isCSSMod(mod)

// Skip all modules from the pages folder. CSS modules are a special case
// as they are generated by mini-css-extract-plugin and these modules
Expand Down