Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/guide/backend-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 6 additions & 5 deletions packages/vite/src/node/plugins/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] {
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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')) {
Expand All @@ -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)
}
}