@@ -26,7 +26,7 @@ export function generateCssBundle({
26
26
for ( const id of sortModules ( cssFiles ) ) {
27
27
const { importedIdResolutions } = getModuleInfo ( id ) ?? { } ;
28
28
for ( const resolution of importedIdResolutions ?? [ ] ) {
29
- if ( resolution . meta . css ) {
29
+ if ( resolution . meta . css && ! extractedCssIds . has ( resolution . id ) ) {
30
30
extractedCssIds . add ( resolution . id ) ;
31
31
cssBundle . addSource ( {
32
32
filename : resolution . id ,
@@ -40,20 +40,23 @@ export function generateCssBundle({
40
40
}
41
41
42
42
/** [id, order] tuple meant for ordering imports */
43
- export type ImportChain = [ string , number ] [ ] ;
43
+ export type ImportChain = [ id : string , order : number ] [ ] ;
44
44
45
45
/** Trace a file back through its importers, building an ordered list */
46
46
export function buildImportChain (
47
47
id : string ,
48
48
{ getModuleInfo, warn } : Pick < PluginContext , 'getModuleInfo' | 'warn' > ,
49
49
) : ImportChain {
50
- let mod : ModuleInfo = getModuleInfo ( id ) ! ;
50
+ let mod : ModuleInfo | null = getModuleInfo ( id ) ! ;
51
+ if ( ! mod ) {
52
+ return [ ] ;
53
+ }
51
54
/** [id, order] */
52
55
const chain : ImportChain = [ [ id , - 1 ] ] ;
53
56
// resolve upwards to root entry
54
57
while ( ! mod . isEntry ) {
55
58
const { id : currentId , importers } = mod ;
56
- const lastImporterId = importers . at ( - 1 ) ! ;
59
+ const lastImporterId = importers . at ( - 1 ) ;
57
60
if ( ! lastImporterId ) {
58
61
break ;
59
62
}
@@ -65,7 +68,7 @@ export function buildImportChain(
65
68
) ;
66
69
break ;
67
70
}
68
- mod = getModuleInfo ( lastImporterId ) ! ;
71
+ mod = getModuleInfo ( lastImporterId ) ;
69
72
if ( ! mod ) {
70
73
break ;
71
74
}
0 commit comments