@@ -23,7 +23,8 @@ import {
23
23
checkPublicFile ,
24
24
assetUrlRE ,
25
25
urlToBuiltUrl ,
26
- getAssetFilename
26
+ getAssetFilename ,
27
+ getAssetHash
27
28
} from './asset'
28
29
import { isCSSRequest } from './css'
29
30
import { modulePreloadPolyfillId } from './modulePreloadPolyfill'
@@ -44,7 +45,7 @@ interface ScriptAssetsUrl {
44
45
}
45
46
46
47
const htmlProxyRE = / \? h t m l - p r o x y = ? [ & i n l i n e \- c s s ] * & i n d e x = ( \d + ) \. ( j s | c s s ) $ /
47
- const inlineCSSRE = / _ _ V I T E _ I N L I N E _ C S S _ _ ( [ ^ _ ] + _ \d + ) _ _ / g
48
+ const inlineCSSRE = / _ _ V I T E _ I N L I N E _ C S S _ _ ( [ a - z \d ] { 8 } _ \d + ) _ _ / g
48
49
// Do not allow preceding '.', but do allow preceding '...' for spread operations
49
50
const inlineImportRE =
50
51
/ (?< ! (?< ! \. \. ) \. ) \b i m p o r t \s * \( ( " ( [ ^ " ] | (?< = \\ ) " ) * " | ' ( [ ^ ' ] | (?< = \\ ) ' ) * ' ) \) / g
@@ -62,8 +63,8 @@ export const htmlProxyMap = new WeakMap<
62
63
> ( )
63
64
64
65
// HTML Proxy Transform result are stored by config
65
- // `${importer}_${query.index}` -> transformed css code
66
- // PS: key like `/vite/packages/playground/assets/index.html_1`
66
+ // `${hash( importer) }_${query.index}` -> transformed css code
67
+ // PS: key like `hash( /vite/packages/playground/assets/index.html)_1`)
67
68
export const htmlProxyResult = new Map < string , string > ( )
68
69
69
70
export function htmlInlineProxyPlugin ( config : ResolvedConfig ) : Plugin {
@@ -373,12 +374,12 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
373
374
addToHTMLProxyCache ( config , filePath , inlineModuleIndex , { code } )
374
375
// will transform with css plugin and cache result with css-post plugin
375
376
js += `\nimport "${ id } ?html-proxy&inline-css&index=${ inlineModuleIndex } .css"`
376
-
377
+ const hash = getAssetHash ( cleanUrl ( id ) )
377
378
// will transform in `applyHtmlTransforms`
378
379
s . overwrite (
379
380
styleNode . loc . start . offset ,
380
381
styleNode . loc . end . offset ,
381
- `"__VITE_INLINE_CSS__${ cleanUrl ( id ) } _${ inlineModuleIndex } __"` ,
382
+ `"__VITE_INLINE_CSS__${ hash } _${ inlineModuleIndex } __"` ,
382
383
{ contentOnly : true }
383
384
)
384
385
}
@@ -392,12 +393,12 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
392
393
code : styleNode . content
393
394
} )
394
395
js += `\nimport "${ id } ?html-proxy&inline-css&index=${ inlineModuleIndex } .css"`
395
-
396
+ const hash = getAssetHash ( cleanUrl ( id ) )
396
397
// will transform in `applyHtmlTransforms`
397
398
s . overwrite (
398
399
styleNode . loc . start . offset ,
399
400
styleNode . loc . end . offset ,
400
- `__VITE_INLINE_CSS__${ cleanUrl ( id ) } _${ inlineModuleIndex } __` ,
401
+ `__VITE_INLINE_CSS__${ hash } _${ inlineModuleIndex } __` ,
401
402
{ contentOnly : true }
402
403
)
403
404
}
0 commit comments