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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -62,15 +62,15 @@ If you need a custom integration, you can follow the steps in this guide to conf

```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
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const assetCache = new WeakMap<Environment, Map<string, string>>()
// For the manifest, we need to preserve the original file path and isEntry
// for CSS assets. We keep a map from referenceId to this information.
export interface GeneratedAssetMeta {
originalFileName: string
originalFileName?: string
isEntry?: boolean
}
export const generatedAssetsMap = new WeakMap<
Expand Down
14 changes: 8 additions & 6 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,8 @@ export function manifestPlugin(): Plugin {
manifest[getChunkName(chunk)] = createChunk(chunk)
} else if (chunk.type === 'asset' && typeof chunk.name === 'string') {
// Add every unique asset to the manifest, keyed by its original name
const src = chunk.originalFileName ?? chunk.name
const src =
chunk.originalFileName ?? '_' + path.basename(chunk.fileName)
const isEntry = entryCssAssetFileNames.has(chunk.fileName)
const asset = createAsset(chunk, src, isEntry)

Expand All @@ -166,7 +170,7 @@ export function manifestPlugin(): Plugin {

// Add deduplicated assets to the manifest
for (const [referenceId, { originalFileName }] of assets.entries()) {
if (!manifest[originalFileName]) {
if (originalFileName && !manifest[originalFileName]) {
const fileName = this.getFileName(referenceId)
const asset = fileNameToAsset.get(fileName)
if (asset) {
Expand Down Expand Up @@ -196,7 +200,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 @@ -205,7 +209,5 @@ export function getChunkOriginalFileName(
name = name.slice(0, endPos) + `-legacy` + ext
}
return name.replace(/\0/g, '')
} else {
return `_` + path.basename(chunk.fileName)
}
}