Skip to content

Commit

Permalink
fix: css extension
Browse files Browse the repository at this point in the history
  • Loading branch information
jessarcher committed Jun 10, 2022
1 parent 1919d04 commit fabc52b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/vite/src/node/plugins/css.ts
Expand Up @@ -488,6 +488,10 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
return chunkCSS
}

function ensureFileExt(name: string, ext: string) {
return path.format({ ...path.parse(name), base: undefined, ext })
}

if (config.build.cssCodeSplit) {
if (isPureCssChunk) {
// this is a shared CSS-only chunk that is empty.
Expand All @@ -498,16 +502,19 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
opts.format === 'cjs' ||
opts.format === 'system'
) {
const cssAssetName = chunk.name + '.css'
const cssAssetName = ensureFileExt(
chunk.facadeModuleId
? normalizePath(path.relative(config.root, chunk.facadeModuleId))
: chunk.name,
'.css'
)

chunkCSS = resolveAssetUrlsInCss(chunkCSS, cssAssetName)
chunkCSS = await finalizeCss(chunkCSS, true, config)

// emit corresponding css file
const fileHandle = this.emitFile({
name: chunk.facadeModuleId
? normalizePath(path.relative(config.root, chunk.facadeModuleId))
: cssAssetName,
name: cssAssetName,
type: 'asset',
source: chunkCSS
})
Expand Down

0 comments on commit fabc52b

Please sign in to comment.