Skip to content

Commit

Permalink
chore: build assets with the entry name when it is an entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
aleen42 committed Jan 6, 2023
1 parent 691e432 commit 79777fc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
7 changes: 5 additions & 2 deletions packages/vite/src/node/plugins/css.ts
Expand Up @@ -553,8 +553,12 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
? normalizePath(path.relative(config.root, chunk.facadeModuleId))
: chunk.name

const isEntry = chunk.isEntry && isPureCssChunk
const lang = path.extname(cssAssetName).slice(1)
const cssFileName = ensureFileExt(cssAssetName, '.css')
const cssFileName = ensureFileExt(
isEntry ? chunk.name : cssAssetName,
'.css',
)

chunkCSS = resolveAssetUrlsInCss(chunkCSS, cssAssetName)
chunkCSS = await finalizeCss(chunkCSS, true, config)
Expand All @@ -566,7 +570,6 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
source: chunkCSS,
})
const originalName = isPreProcessor(lang) ? cssAssetName : cssFileName
const isEntry = chunk.isEntry && isPureCssChunk
generatedAssets
.get(config)!
.set(referenceId, { originalName, isEntry })
Expand Down
Expand Up @@ -37,7 +37,6 @@ describe.runIf(isBuild)('build', () => {
const cssAssetEntry = manifest['global.css']
const scssAssetEntry = manifest['nested/blue.scss']
const imgAssetEntry = manifest['../images/logo.png']
const dirFooAssetEntry = manifest['../../dir/foo.css'] // '\\' should not be used even on windows
expect(htmlEntry.css.length).toEqual(1)
expect(htmlEntry.assets.length).toEqual(1)
expect(cssAssetEntry?.file).not.toBeUndefined()
Expand All @@ -47,7 +46,9 @@ describe.runIf(isBuild)('build', () => {
expect(scssAssetEntry?.isEntry).toEqual(true)
expect(imgAssetEntry?.file).not.toBeUndefined()
expect(imgAssetEntry?.isEntry).toBeUndefined()
expect(dirFooAssetEntry).not.toBeUndefined()
// use the entry name
expect(manifest['bar.css']).not.toBeUndefined()
expect(manifest['foo.css']).toBeUndefined()
})
})

Expand Down
2 changes: 1 addition & 1 deletion playground/backend-integration/vite.config.js
Expand Up @@ -19,7 +19,7 @@ function BackendIntegrationExample() {
.map((filename) => [path.relative(root, filename), filename])

entrypoints.push(['tailwindcss-colors', 'tailwindcss/colors.js'])
entrypoints.push(['foo.css', path.resolve(__dirname, './dir/foo.css')])
entrypoints.push(['bar.css', path.resolve(__dirname, './dir/foo.css')])

return {
build: {
Expand Down

0 comments on commit 79777fc

Please sign in to comment.