Skip to content
Open
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
17 changes: 16 additions & 1 deletion packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,22 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {

const removedPureCssFiles = removedPureCssFilesCache.get(config)!
pureCssChunkNames.forEach((fileName) => {
removedPureCssFiles.set(fileName, bundle[fileName] as RenderedChunk)
const emptyJsPlaceholder = bundle[fileName] as RenderedChunk
if (emptyJsPlaceholder.isEntry) {
const { importedAssets, importedCss } =
emptyJsPlaceholder.viteMetadata!
const cssReferenceId = cssEntriesMap
.get(this.environment)!
.get(emptyJsPlaceholder.name)!
const realCssEntryName = this.getFileName(cssReferenceId)
const realCssEntry = bundle[realCssEntryName]!
importedCss.delete(realCssEntryName)
if (importedAssets.size || importedCss.size) {
realCssEntry.viteMetadata = { importedAssets, importedCss }
}
}

removedPureCssFiles.set(fileName, emptyJsPlaceholder)
delete bundle[fileName]
delete bundle[`${fileName}.map`]
})
Expand Down
7 changes: 7 additions & 0 deletions packages/vite/src/node/plugins/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ export function manifestPlugin(): Plugin {
manifestChunk.name = name
// @ts-expect-error keep names field for backward compatibility
manifestChunk.names = asset.names

if (asset.viteMetadata?.importedCss.size) {
manifestChunk.css = [...asset.viteMetadata.importedCss]
}
if (asset.viteMetadata?.importedAssets.size) {
manifestChunk.assets = [...asset.viteMetadata.importedAssets]
}
}
return manifestChunk
}
Expand Down
4 changes: 4 additions & 0 deletions packages/vite/types/metadata.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export interface CustomPluginOptionsVite {
}

declare module 'rollup' {
export interface OutputAsset {
viteMetadata?: ChunkMetadata
}

export interface RenderedChunk {
viteMetadata?: ChunkMetadata
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe.runIf(isBuild)('build', () => {
// use the entry name
expect(dirFooAssetEntry.file).toMatch('assets/bar-')
expect(dirFooAssetEntry.name).toStrictEqual('bar.css')
expect(dirFooAssetEntry.assets.length).toEqual(1)
expect(customNameAssetEntry.name).toStrictEqual('bar.custom')
expect(iconEntrypointEntry?.file).not.toBeUndefined()
expect(waterContainerEntry?.file).not.toBeUndefined()
Expand Down
5 changes: 5 additions & 0 deletions playground/backend-integration/dir/foo-background.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions playground/backend-integration/dir/foo.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.windows-path-foo {
color: blue;
}
.foo-background-image {
background-image: url('./foo-background.svg?no-inline');
}