Skip to content

Commit

Permalink
revert: remove css chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin committed Aug 8, 2024
1 parent ededbc2 commit d76d483
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,9 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
generatedAssets
.get(config)!
.set(referenceId, { originalName: originalFilename, isEntry })
getChunkMetadata(chunk.name)!.importedCss.add(this.getFileName(referenceId))
getChunkMetadata(chunk.name)!.importedCss.add(
this.getFileName(referenceId),
)
} else if (!config.build.ssr) {
// legacy build and inline css

Expand Down Expand Up @@ -929,7 +931,9 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
// chunks instead.
chunk.imports = chunk.imports.filter((file) => {
if (pureCssChunkNames.includes(file)) {
const { importedCss, importedAssets } = getChunkMetadata((bundle[file] as OutputChunk).name)!
const { importedCss, importedAssets } = getChunkMetadata(
(bundle[file] as OutputChunk).name,
)!
importedCss.forEach((file) =>
getChunkMetadata(chunk.name)!.importedCss.add(file),
)
Expand All @@ -947,14 +951,12 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
}
}

// TODO The css module will be treated as a common-js like module, remove it from the bundle

// const removedPureCssFiles = removedPureCssFilesCache.get(config)!
// pureCssChunkNames.forEach((fileName) => {
// removedPureCssFiles.set(fileName, bundle[fileName] as RenderedChunk)
// delete bundle[fileName]
// delete bundle[`${fileName}.map`]
// })
const removedPureCssFiles = removedPureCssFilesCache.get(config)!
pureCssChunkNames.forEach((fileName) => {
removedPureCssFiles.set(fileName, bundle[fileName] as RenderedChunk)
delete bundle[fileName]
delete bundle[`${fileName}.map`]
})
}
},
}
Expand Down Expand Up @@ -2833,7 +2835,8 @@ function formatStylusSourceMap(
if (!mapBefore) return undefined
const map = { ...mapBefore }

const resolveFromRoot = (p: string | null) => normalizePath(path.resolve(root, p!))
const resolveFromRoot = (p: string | null) =>
normalizePath(path.resolve(root, p!))

if (map.file) {
map.file = resolveFromRoot(map.file)
Expand Down

0 comments on commit d76d483

Please sign in to comment.