@@ -626,12 +626,7 @@ export function createCompilerPlugin(
626626 angularCompilationContext . markAsReady ( hasCompilationErrors ) ;
627627 }
628628
629- // Merge in key order: the map fills in completion order, and when two entries share an
630- // output file the last one merged wins, so the metafile would otherwise vary between builds.
631- const sortedResults = [ ...additionalResults ] . sort ( ( [ a ] , [ b ] ) =>
632- a < b ? - 1 : a > b ? 1 : 0 ,
633- ) ;
634- for ( const [ , { outputFiles, metafile } ] of sortedResults ) {
629+ for ( const { outputFiles, metafile } of additionalResults . values ( ) ) {
635630 // Add any additional output files to the main output files
636631 if ( outputFiles ?. length ) {
637632 result . outputFiles ?. push ( ...outputFiles ) ;
@@ -643,7 +638,15 @@ export function createCompilerPlugin(
643638 // mitigating significant performance overhead for large apps.
644639 // See: https://bugs.chromium.org/p/v8/issues/detail?id=11536
645640 Object . assign ( result . metafile . inputs , metafile . inputs ) ;
646- Object . assign ( result . metafile . outputs , metafile . outputs ) ;
641+ for ( const [ outputPath , output ] of Object . entries ( metafile . outputs ) ) {
642+ // Two stylesheets can bundle to the same output file. Union the inputs into a new
643+ // object so every input is attributed and the bundler's cached metafile is untouched.
644+ const existing : Metafile [ 'outputs' ] [ string ] | undefined =
645+ result . metafile . outputs [ outputPath ] ;
646+ result . metafile . outputs [ outputPath ] = existing
647+ ? { ...existing , inputs : { ...existing . inputs , ...output . inputs } }
648+ : output ;
649+ }
647650 }
648651 }
649652
0 commit comments