Skip to content

Commit

Permalink
fix: depend on the resolved config
Browse files Browse the repository at this point in the history
  • Loading branch information
crcong committed Aug 13, 2021
1 parent 1ec98f3 commit 02b7558
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 7 additions & 3 deletions packages/vite/src/node/plugins/css.ts
Expand Up @@ -120,7 +120,10 @@ export const chunkToEmittedCssFileMap = new WeakMap<
Set<string>
>()

export const removedPureCssFiles = new Map<string, RenderedChunk>()
export const removedPureCssFilesCache = new WeakMap<
ResolvedConfig,
Map<string, RenderedChunk>
>()

const postcssConfigCache = new WeakMap<
ResolvedConfig,
Expand Down Expand Up @@ -153,7 +156,7 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
moduleCache = new Map<string, Record<string, string>>()
cssModulesCache.set(config, moduleCache)

removedPureCssFiles.clear()
removedPureCssFilesCache.set(config, new Map<string, RenderedChunk>())
},

async transform(raw, id) {
Expand Down Expand Up @@ -475,8 +478,9 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
)
}
}
const removedPureCssFiles = removedPureCssFilesCache.get(config)
pureCssChunks.forEach((fileName) => {
removedPureCssFiles.set(fileName, bundle[fileName] as RenderedChunk)
removedPureCssFiles!.set(fileName, bundle[fileName] as RenderedChunk)
delete bundle[fileName]
})
}
Expand Down
6 changes: 4 additions & 2 deletions packages/vite/src/node/plugins/importAnalysisBuild.ts
Expand Up @@ -4,7 +4,7 @@ import { Plugin } from '../plugin'
import MagicString from 'magic-string'
import { ImportSpecifier, init, parse as parseImports } from 'es-module-lexer'
import { OutputChunk } from 'rollup'
import { chunkToEmittedCssFileMap, removedPureCssFiles } from './css'
import { chunkToEmittedCssFileMap, removedPureCssFilesCache } from './css'
import { transformImportGlob } from '../importGlob'

/**
Expand Down Expand Up @@ -257,7 +257,9 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
}
chunk.imports.forEach(addDeps)
} else {
const chunk = removedPureCssFiles.get(filename)
const removedPureCssFiles =
removedPureCssFilesCache.get(config)
const chunk = removedPureCssFiles!.get(filename)
if (chunk) {
const cssFiles = chunkToEmittedCssFileMap.get(chunk)
if (cssFiles && cssFiles.size > 0) {
Expand Down

0 comments on commit 02b7558

Please sign in to comment.