Skip to content

Commit

Permalink
fix(CSSEntryPoints): name CSS entries as original entries
Browse files Browse the repository at this point in the history
Signed-off-by: Grigorii K. Shartsev <me@shgk.me>
  • Loading branch information
ShGKme authored and backportbot[bot] committed Jun 20, 2024
1 parent 47a33b7 commit b59c21f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/plugins/CSSEntryPoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import type { OutputOptions, PreRenderedAsset } from 'rollup'
import type { Plugin } from 'vite'

import { basename, dirname, join, normalize } from 'path'
import { basename, dirname, join, normalize, extname } from 'path'

interface CSSEntryPointsPluginOptions {
/**
Expand Down Expand Up @@ -97,8 +97,13 @@ export function CSSEntryPointsPlugin(options?: CSSEntryPointsPluginOptions) {
.map((css) => `@import './${basename(css)}';`)
.join('\n')

const cssName = `${chunk.name}.css`
// Name new CSS entry same as the entry
const entryName = basename(chunk.fileName).slice(0, -1 * extname(chunk.fileName).length)
const cssName = `${entryName}.css`

// Keep original path
const path = dirname(typeof options.assetFileNames === 'string' ? options.assetFileNames : options.assetFileNames({ type: 'asset', source: '', name: 'name.css' }))

this.emitFile({
type: 'asset',
name: `\0${cssName}`,
Expand All @@ -107,6 +112,6 @@ export function CSSEntryPointsPlugin(options?: CSSEntryPointsPluginOptions) {
source: `/* extracted by css-entry-points-plugin */\n${source}`,
})
}
}
},
} as Plugin
}

0 comments on commit b59c21f

Please sign in to comment.