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(css): prevent commonjs-proxy module been bundled into css chunk w… #2160

Merged
merged 1 commit into from
Feb 26, 2021
Merged
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
11 changes: 8 additions & 3 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const cssLangs = `\\.(css|less|sass|scss|styl|stylus|postcss)($|\\?)`
const cssLangRE = new RegExp(cssLangs)
const cssModuleRE = new RegExp(`\\.module${cssLangs}`)
const directRequestRE = /(\?|&)direct\b/
const commjsProxyRE = /\?commonjs-proxy/

export const isCSSRequest = (request: string) =>
cssLangRE.test(request) && !directRequestRE.test(request)
Expand Down Expand Up @@ -118,7 +119,7 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
},

async transform(raw, id) {
if (!cssLangRE.test(id)) {
if (!cssLangRE.test(id) || commjsProxyRE.test(id)) {
return
}

Expand Down Expand Up @@ -215,7 +216,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
name: 'vite:css-post',

transform(css, id, ssr) {
if (!cssLangRE.test(id)) {
if (!cssLangRE.test(id) || commjsProxyRE.test(id)) {
return
}

Expand Down Expand Up @@ -264,7 +265,11 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
let isPureCssChunk = true
const ids = Object.keys(chunk.modules)
for (const id of ids) {
if (!isCSSRequest(id) || cssModuleRE.test(id)) {
if (
!isCSSRequest(id) ||
cssModuleRE.test(id) ||
commjsProxyRE.test(id)
) {
isPureCssChunk = false
}
if (styles.has(id)) {
Expand Down