Skip to content

Commit

Permalink
fix: Also add hash to css
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux authored and backportbot[bot] committed Aug 5, 2024
1 parent a29591a commit cab7917
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions __tests__/css-entry-points.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
* SPDX-License-Identifier: MIT
*/

// eslint-disable-next-line n/no-extraneous-import
import type { RollupOutput, OutputAsset } from 'rollup'

import { build } from 'vite'
import { describe, it, expect } from 'vitest'
import { CSSEntryPointsPlugin } from '../lib/plugins/CSSEntryPoints'
Expand Down
8 changes: 6 additions & 2 deletions lib/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const createAppConfig = (entries: { [entryAlias: string]: string }, optio
EmptyJSDirPlugin(
typeof options.emptyOutputDirectory === 'object'
? options.emptyOutputDirectory
: undefined
: undefined,
),
)
}
Expand Down Expand Up @@ -211,6 +211,10 @@ export const createAppConfig = (entries: { [entryAlias: string]: string }, optio
if (/png|jpe?g|svg|gif|tiff|bmp|ico/i.test(extType)) {
return 'img/[name][extname]'
} else if (/css/i.test(extType)) {
if (userConfig.build?.cssCodeSplit !== false) {
// we need hashed css name for css chunks as a cache buster
return 'css/[name]-[hash].css'
}
return `css/${assetsPrefix}[name].css`
} else if (/woff2?|ttf|otf/i.test(extType)) {
return 'css/fonts/[name][extname]'
Expand All @@ -221,7 +225,7 @@ export const createAppConfig = (entries: { [entryAlias: string]: string }, optio
return `js/${assetsPrefix}[name].mjs`
},
chunkFileNames: () => {
return 'js/chunks/[name]-[hash].mjs'
return 'js/[name]-[hash].chunk.mjs'
},
manualChunks: {
...(options?.coreJS ? { polyfill: ['core-js'] } : {}),
Expand Down

0 comments on commit cab7917

Please sign in to comment.