fix(manifest): non entry CSS chunk src was wrong (#18133)

This commit is contained in:
翠 / green 2024-10-25 20:16:30 +09:00 committed by GitHub
parent c4e7f34d2e
commit c148676c90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 9 deletions

View File

@ -61,15 +61,15 @@ If you need a custom integration, you can follow the steps in this guide to conf
```json [.vite/manifest.json]
{
"_shared-!~{003}~.js": {
"file": "assets/shared-ChJ_j-JJ.css",
"src": "_shared-!~{003}~.js"
},
"_shared-B7PI925R.js": {
"file": "assets/shared-B7PI925R.js",
"name": "shared",
"css": ["assets/shared-ChJ_j-JJ.css"]
},
"_shared-ChJ_j-JJ.css": {
"file": "assets/shared-ChJ_j-JJ.css",
"src": "_shared-ChJ_j-JJ.css"
},
"baz.js": {
"file": "assets/baz-B2H3sXNv.js",
"name": "baz",

View File

@ -57,7 +57,10 @@ export function manifestPlugin(): Plugin {
const buildOptions = this.environment.config.build
function getChunkName(chunk: OutputChunk) {
return getChunkOriginalFileName(chunk, root, format)
return (
getChunkOriginalFileName(chunk, root, format) ??
`_` + path.basename(chunk.fileName)
)
}
function getInternalImports(imports: string[]): string[] {
@ -150,7 +153,7 @@ export function manifestPlugin(): Plugin {
const src =
chunk.originalFileNames.length > 0
? chunk.originalFileNames[0]
: chunk.names[0]
: '_' + path.basename(chunk.fileName)
const isEntry = entryCssAssetFileNames.has(chunk.fileName)
const asset = createAsset(chunk, src, isEntry)
@ -189,7 +192,7 @@ export function getChunkOriginalFileName(
chunk: OutputChunk | RenderedChunk,
root: string,
format: InternalModuleFormat,
): string {
): string | undefined {
if (chunk.facadeModuleId) {
let name = normalizePath(path.relative(root, chunk.facadeModuleId))
if (format === 'system' && !chunk.name.includes('-legacy')) {
@ -198,7 +201,5 @@ export function getChunkOriginalFileName(
name = name.slice(0, endPos) + `-legacy` + ext
}
return name.replace(/\0/g, '')
} else {
return `_` + path.basename(chunk.fileName)
}
}