Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4abf056

Browse files
CyberAPStanislav Lashmanov
and
Stanislav Lashmanov
authored
fix(build): replacenames in the manifest with unmangledname for CSS assets (#20585)
Co-authored-by: Stanislav Lashmanov <slashmanov@gitlab.com>
1 parent075caa0 commit4abf056

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

‎packages/vite/src/node/plugins/asset.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ export const inlineRE: RegExp = /[?&]inline\b/
4646
constassetCache=newWeakMap<Environment,Map<string,string>>()
4747

4848
/** a set of referenceId for entry CSS assets for each environment */
49-
exportconstcssEntriesMap:WeakMap<Environment,Set<string>>=newWeakMap()
49+
exportconstcssEntriesMap:WeakMap<
50+
Environment,
51+
Map<string,string>
52+
>=newWeakMap()
5053

5154
// add own dictionary entry by directly assigning mrmime
5255
exportfunctionregisterCustomMime():void{
@@ -148,7 +151,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
148151

149152
buildStart(){
150153
assetCache.set(this.environment,newMap())
151-
cssEntriesMap.set(this.environment,newSet())
154+
cssEntriesMap.set(this.environment,newMap())
152155
},
153156

154157
resolveId:{

‎packages/vite/src/node/plugins/css.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
876876
source:chunkCSS,
877877
})
878878
if(isEntry){
879-
cssEntriesMap.get(this.environment)!.add(referenceId)
879+
cssEntriesMap.get(this.environment)!.set(chunk.name,referenceId)
880880
}
881881
chunk.viteMetadata!.importedCss.add(this.getFileName(referenceId))
882882
}elseif(this.environment.config.consumer==='client'){

‎packages/vite/src/node/plugins/manifest.ts‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface ManifestChunk {
2121
assets?:string[]
2222
isEntry?:boolean
2323
name?:string
24-
names?:string[]
24+
//names field is deprecated (removed from types, but still emitted for backward compatibility)
2525
isDynamicEntry?:boolean
2626
imports?:string[]
2727
dynamicImports?:string[]
@@ -122,25 +122,27 @@ export function manifestPlugin(): Plugin {
122122
functioncreateAsset(
123123
asset:OutputAsset,
124124
src:string,
125-
isEntry?:boolean,
125+
name?:string,
126126
):ManifestChunk{
127127
constmanifestChunk:ManifestChunk={
128128
file:asset.fileName,
129129
src,
130130
}
131-
if(isEntry){
131+
if(name){
132132
manifestChunk.isEntry=true
133+
manifestChunk.name=name
134+
//@ts-expect-error keep names field for backward compatibility
133135
manifestChunk.names=asset.names
134136
}
135137
returnmanifestChunk
136138
}
137139

138140
constentryCssReferenceIds=cssEntriesMap.get(this.environment)!
139-
constentryCssAssetFileNames=newSet()
140-
for(constidofentryCssReferenceIds){
141+
constentryCssAssetFileNames=newMap<string,string>()
142+
for(const[name,id]ofentryCssReferenceIds){
141143
try{
142144
constfileName=this.getFileName(id)
143-
entryCssAssetFileNames.add(fileName)
145+
entryCssAssetFileNames.set(fileName,name)
144146
}catch{
145147
// The asset was generated as part of a different output option.
146148
// It was already handled during the previous run of this plugin.
@@ -157,8 +159,8 @@ export function manifestPlugin(): Plugin {
157159
chunk.originalFileNames.length>0
158160
?chunk.originalFileNames[0]
159161
:`_${path.basename(chunk.fileName)}`
160-
constisEntry=entryCssAssetFileNames.has(chunk.fileName)
161-
constasset=createAsset(chunk,src,isEntry)
162+
constname=entryCssAssetFileNames.get(chunk.fileName)
163+
constasset=createAsset(chunk,src,name)
162164

163165
// If JS chunk and asset chunk are both generated from the same source file,
164166
// prioritize JS chunk as it contains more information

‎playground/backend-integration/__tests__/backend-integration.spec.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ describe.runIf(isBuild)('build', () => {
5454
constscssAssetEntry=manifest['nested/blue.scss']
5555
constimgAssetEntry=manifest['../images/logo.png']
5656
constdirFooAssetEntry=manifest['../../dir/foo.css']
57+
constcustomNameAssetEntry=manifest['../../dir/custom.css']
5758
consticonEntrypointEntry=manifest['icon.png']
5859
constwaterContainerEntry=manifest['water-container.svg']
5960
expect(htmlEntry.css.length).toEqual(1)
@@ -74,7 +75,8 @@ describe.runIf(isBuild)('build', () => {
7475
expect(dirFooAssetEntry).not.toBeUndefined()// '\\' should not be used even on windows
7576
// use the entry name
7677
expect(dirFooAssetEntry.file).toMatch('assets/bar-')
77-
expect(dirFooAssetEntry.names).toStrictEqual(['bar.css'])
78+
expect(dirFooAssetEntry.name).toStrictEqual('bar.css')
79+
expect(customNameAssetEntry.name).toStrictEqual('bar.custom')
7880
expect(iconEntrypointEntry?.file).not.toBeUndefined()
7981
expect(waterContainerEntry?.file).not.toBeUndefined()
8082
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.custom {
2+
color: red;
3+
}

‎playground/backend-integration/vite.config.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ function BackendIntegrationExample() {
2323

2424
entrypoints.push(['tailwindcss-colors','tailwindcss/colors.js'])
2525
entrypoints.push(['bar.css',path.resolve(__dirname,'./dir/foo.css')])
26+
entrypoints.push([
27+
'bar.custom',
28+
path.resolve(__dirname,'./dir/custom.css'),
29+
])
2630

2731
return{
2832
server:{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp