@@ -32,14 +32,21 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[]
32
32
function createNameForParentPages ( id : string , ctx : { getModuleInfo : GetModuleInfo } ) : string {
33
33
const parents = Array . from ( getTopLevelPages ( id , ctx ) ) ;
34
34
const firstParentId = parents [ 0 ] ?. [ 0 ] . id ;
35
- const firstParentName = firstParentId ? npath . parse ( firstParentId ) . name : 'index' ;
35
+ const proposedName = createNameHash (
36
+ firstParentId ,
37
+ parents . map ( ( [ page ] ) => page . id )
38
+ ) ;
39
+ return proposedName ;
40
+ }
36
41
42
+ function createNameHash ( baseId : string , hashIds : string [ ] ) : string {
43
+ const baseName = baseId ? npath . parse ( baseId ) . name : 'index' ;
37
44
const hash = crypto . createHash ( 'sha256' ) ;
38
- for ( const [ page ] of parents ) {
39
- hash . update ( page . id , 'utf-8' ) ;
45
+ for ( const id of hashIds ) {
46
+ hash . update ( id , 'utf-8' ) ;
40
47
}
41
48
const h = hash . digest ( 'hex' ) . slice ( 0 , 8 ) ;
42
- const proposedName = firstParentName + '.' + h ;
49
+ const proposedName = baseName + '.' + h ;
43
50
return proposedName ;
44
51
}
45
52
@@ -74,6 +81,15 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[]
74
81
// For CSS, create a hash of all of the pages that use it.
75
82
// This causes CSS to be built into shared chunks when used by multiple pages.
76
83
if ( isCSSRequest ( id ) ) {
84
+ for ( const [ pageInfo ] of walkParentInfos ( id , {
85
+ getModuleInfo : args [ 0 ] . getModuleInfo ,
86
+ } ) ) {
87
+ if ( pageInfo . id . endsWith ( DELAYED_ASSET_FLAG ) ) {
88
+ // Split delayed assets to separate modules
89
+ // so they can be injected where needed
90
+ return createNameHash ( id , [ id ] ) ;
91
+ }
92
+ }
77
93
return createNameForParentPages ( id , args [ 0 ] ) ;
78
94
}
79
95
} ;
0 commit comments