@@ -77,8 +77,9 @@ class MiniCssExtractPlugin {
77
77
}
78
78
79
79
readableIdentifier ( requestShortener ) {
80
- return `css ${ requestShortener . shorten ( this . _identifier ) } ${ this . _identifierIndex ? ` (${ this . _identifierIndex } )` : ""
81
- } `;
80
+ return `css ${ requestShortener . shorten ( this . _identifier ) } ${
81
+ this . _identifierIndex ? ` (${ this . _identifierIndex } )` : ""
82
+ } `;
82
83
}
83
84
84
85
// eslint-disable-next-line class-methods-use-this
@@ -442,7 +443,7 @@ class MiniCssExtractPlugin {
442
443
443
444
class CssDependencyTemplate {
444
445
// eslint-disable-next-line class-methods-use-this
445
- apply ( ) { }
446
+ apply ( ) { }
446
447
}
447
448
448
449
compilation . dependencyTemplates . set (
@@ -580,22 +581,22 @@ class MiniCssExtractPlugin {
580
581
'var linkTag = document.createElement("link");' ,
581
582
this . runtimeOptions . attributes
582
583
? Template . asString (
583
- Object . entries ( this . runtimeOptions . attributes ) . map (
584
- ( entry ) => {
585
- const [ key , value ] = entry ;
586
-
587
- return `linkTag.setAttribute(${ JSON . stringify (
588
- key
589
- ) } , ${ JSON . stringify ( value ) } );`;
590
- }
584
+ Object . entries ( this . runtimeOptions . attributes ) . map (
585
+ ( entry ) => {
586
+ const [ key , value ] = entry ;
587
+
588
+ return `linkTag.setAttribute(${ JSON . stringify (
589
+ key
590
+ ) } , ${ JSON . stringify ( value ) } );`;
591
+ }
592
+ )
591
593
)
592
- )
593
594
: "" ,
594
595
'linkTag.rel = "stylesheet";' ,
595
596
this . runtimeOptions . linkType
596
597
? `linkTag.type = ${ JSON . stringify (
597
- this . runtimeOptions . linkType
598
- ) } ;`
598
+ this . runtimeOptions . linkType
599
+ ) } ;`
599
600
: "" ,
600
601
`var onLinkComplete = ${ runtimeTemplate . basicFunction ( "event" , [
601
602
"// avoid mem leaks." ,
@@ -619,22 +620,22 @@ class MiniCssExtractPlugin {
619
620
"linkTag.href = fullhref;" ,
620
621
crossOriginLoading
621
622
? Template . asString ( [
622
- `if (linkTag.href.indexOf(window.location.origin + '/') !== 0) {` ,
623
- Template . indent (
624
- `linkTag.crossOrigin = ${ JSON . stringify (
625
- crossOriginLoading
626
- ) } ;`
627
- ) ,
628
- "}" ,
629
- ] )
623
+ `if (linkTag.href.indexOf(window.location.origin + '/') !== 0) {` ,
624
+ Template . indent (
625
+ `linkTag.crossOrigin = ${ JSON . stringify (
626
+ crossOriginLoading
627
+ ) } ;`
628
+ ) ,
629
+ "}" ,
630
+ ] )
630
631
: "" ,
631
632
typeof this . runtimeOptions . insert !== "undefined"
632
633
? typeof this . runtimeOptions . insert === "function"
633
634
? `(${ this . runtimeOptions . insert . toString ( ) } )(linkTag)`
634
635
: Template . asString ( [
635
- `var target = document.querySelector("${ this . runtimeOptions . insert } ");` ,
636
- `target.parentNode.insertBefore(linkTag, target.nextSibling);` ,
637
- ] )
636
+ `var target = document.querySelector("${ this . runtimeOptions . insert } ");` ,
637
+ `target.parentNode.insertBefore(linkTag, target.nextSibling);` ,
638
+ ] )
638
639
: Template . asString ( [ "document.head.appendChild(linkTag);" ] ) ,
639
640
"return linkTag;" ,
640
641
]
@@ -666,98 +667,114 @@ class MiniCssExtractPlugin {
666
667
"resolve, reject" ,
667
668
[
668
669
`var href = ${ RuntimeGlobals . require } .miniCssF(chunkId);` ,
669
- `var fullhref = ${ RuntimeGlobals . publicPath } + href;` ,
670
+ `var fetchRTL = ${
671
+ this . runtimeOptions . globalRTLFlag
672
+ ? `window['${ this . runtimeOptions . globalRTLFlag } ']`
673
+ : false
674
+ } ;`,
675
+ `var fullhref = ${
676
+ this . runtimeOptions . outputPublicPath
677
+ ? `'${ this . runtimeOptions . outputPublicPath } '`
678
+ : RuntimeGlobals . publicPath
679
+ } + href;`,
670
680
"if(findStylesheet(href, fullhref)) return resolve();" ,
681
+ "if (fetchRTL) {" ,
682
+ Template . indent ( [
683
+ `fullhref = fullhref.replace(/\\.css/i, '.rtl.css');` ,
684
+ ] ) ,
685
+ "}" ,
671
686
"createStylesheet(chunkId, fullhref, resolve, reject);" ,
672
687
]
673
688
) } );`
674
689
) } `,
675
690
withLoading
676
691
? Template . asString ( [
677
- "// object to store loaded CSS chunks" ,
678
- "var installedCssChunks = {" ,
679
- Template . indent (
680
- chunk . ids
681
- . map ( ( id ) => `${ JSON . stringify ( id ) } : 0` )
682
- . join ( ",\n" )
683
- ) ,
684
- "};" ,
685
- "" ,
686
- `${ RuntimeGlobals . ensureChunkHandlers
687
- } .miniCss = ${ runtimeTemplate . basicFunction (
688
- "chunkId, promises" ,
689
- [
690
- `var cssChunks = ${ JSON . stringify ( chunkMap ) } ;` ,
691
- "if(installedCssChunks[chunkId]) promises.push(installedCssChunks[chunkId]);" ,
692
- "else if(installedCssChunks[chunkId] !== 0 && cssChunks[chunkId]) {" ,
693
- Template . indent ( [
694
- `promises.push(installedCssChunks[chunkId] = loadStylesheet(chunkId).then(${ runtimeTemplate . basicFunction (
695
- "" ,
696
- "installedCssChunks[chunkId] = 0;"
697
- ) } , ${ runtimeTemplate . basicFunction ( "e" , [
698
- "delete installedCssChunks[chunkId];" ,
699
- "throw e;" ,
700
- ] ) } ));`,
701
- ] ) ,
702
- "}" ,
703
- ]
704
- ) } ;`,
705
- ] )
692
+ "// object to store loaded CSS chunks" ,
693
+ "var installedCssChunks = {" ,
694
+ Template . indent (
695
+ chunk . ids
696
+ . map ( ( id ) => `${ JSON . stringify ( id ) } : 0` )
697
+ . join ( ",\n" )
698
+ ) ,
699
+ "};" ,
700
+ "" ,
701
+ `${
702
+ RuntimeGlobals . ensureChunkHandlers
703
+ } .miniCss = ${ runtimeTemplate . basicFunction (
704
+ "chunkId, promises" ,
705
+ [
706
+ `var cssChunks = ${ JSON . stringify ( chunkMap ) } ;` ,
707
+ "if(installedCssChunks[chunkId]) promises.push(installedCssChunks[chunkId]);" ,
708
+ "else if(installedCssChunks[chunkId] !== 0 && cssChunks[chunkId]) {" ,
709
+ Template . indent ( [
710
+ `promises.push(installedCssChunks[chunkId] = loadStylesheet(chunkId).then(${ runtimeTemplate . basicFunction (
711
+ "" ,
712
+ "installedCssChunks[chunkId] = 0;"
713
+ ) } , ${ runtimeTemplate . basicFunction ( "e" , [
714
+ "delete installedCssChunks[chunkId];" ,
715
+ "throw e;" ,
716
+ ] ) } ));`,
717
+ ] ) ,
718
+ "}" ,
719
+ ]
720
+ ) } ;`,
721
+ ] )
706
722
: "// no chunk loading" ,
707
723
"" ,
708
724
withHmr
709
725
? Template . asString ( [
710
- "var oldTags = [];" ,
711
- "var newTags = [];" ,
712
- `var applyHandler = ${ runtimeTemplate . basicFunction (
713
- "options" ,
714
- [
715
- `return { dispose: ${ runtimeTemplate . basicFunction ( "" , [
716
- "for(var i = 0; i < oldTags.length; i++) {" ,
717
- Template . indent ( [
718
- "var oldTag = oldTags[i];" ,
719
- "if(oldTag.parentNode) oldTag.parentNode.removeChild(oldTag);" ,
720
- ] ) ,
721
- "}" ,
722
- "oldTags.length = 0;" ,
723
- ] ) } , apply: ${ runtimeTemplate . basicFunction ( "" , [
724
- 'for(var i = 0; i < newTags.length; i++) newTags[i].rel = "stylesheet";' ,
725
- "newTags.length = 0;" ,
726
- ] ) } };`,
727
- ]
728
- ) } `,
729
- `${ RuntimeGlobals . hmrDownloadUpdateHandlers
730
- } .miniCss = ${ runtimeTemplate . basicFunction (
731
- "chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList" ,
732
- [
733
- "applyHandlers.push(applyHandler);" ,
734
- `chunkIds.forEach(${ runtimeTemplate . basicFunction (
735
- "chunkId" ,
736
- [
737
- `var href = ${ RuntimeGlobals . require } .miniCssF(chunkId);` ,
738
- `var fullhref = ${ RuntimeGlobals . publicPath } + href;` ,
739
- "var oldTag = findStylesheet(href, fullhref);" ,
740
- "if(!oldTag) return;" ,
741
- `promises.push(new Promise(${ runtimeTemplate . basicFunction (
742
- "resolve, reject" ,
743
- [
744
- `var tag = createStylesheet(chunkId, fullhref, ${ runtimeTemplate . basicFunction (
745
- "" ,
746
- [
747
- 'tag.as = "style";' ,
748
- 'tag.rel = "preload";' ,
749
- "resolve();" ,
750
- ]
751
- ) } , reject);`,
752
- "oldTags.push(oldTag);" ,
753
- "newTags.push(tag);" ,
754
- ]
755
- ) } ));`,
756
- ]
757
- ) } );`,
758
- ]
759
- ) } `,
760
- ] )
726
+ "var oldTags = [];" ,
727
+ "var newTags = [];" ,
728
+ `var applyHandler = ${ runtimeTemplate . basicFunction (
729
+ "options" ,
730
+ [
731
+ `return { dispose: ${ runtimeTemplate . basicFunction ( "" , [
732
+ "for(var i = 0; i < oldTags.length; i++) {" ,
733
+ Template . indent ( [
734
+ "var oldTag = oldTags[i];" ,
735
+ "if(oldTag.parentNode) oldTag.parentNode.removeChild(oldTag);" ,
736
+ ] ) ,
737
+ "}" ,
738
+ "oldTags.length = 0;" ,
739
+ ] ) } , apply: ${ runtimeTemplate . basicFunction ( "" , [
740
+ 'for(var i = 0; i < newTags.length; i++) newTags[i].rel = "stylesheet";' ,
741
+ "newTags.length = 0;" ,
742
+ ] ) } };`,
743
+ ]
744
+ ) } `,
745
+ `${
746
+ RuntimeGlobals . hmrDownloadUpdateHandlers
747
+ } .miniCss = ${ runtimeTemplate . basicFunction (
748
+ "chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList" ,
749
+ [
750
+ "applyHandlers.push(applyHandler);" ,
751
+ `chunkIds.forEach(${ runtimeTemplate . basicFunction (
752
+ "chunkId" ,
753
+ [
754
+ `var href = ${ RuntimeGlobals . require } .miniCssF(chunkId);` ,
755
+ `var fullhref = ${ RuntimeGlobals . publicPath } + href;` ,
756
+ "var oldTag = findStylesheet(href, fullhref);" ,
757
+ "if(!oldTag) return;" ,
758
+ `promises.push(new Promise(${ runtimeTemplate . basicFunction (
759
+ "resolve, reject" ,
760
+ [
761
+ `var tag = createStylesheet(chunkId, fullhref, ${ runtimeTemplate . basicFunction (
762
+ "" ,
763
+ [
764
+ 'tag.as = "style";' ,
765
+ 'tag.rel = "preload";' ,
766
+ "resolve();" ,
767
+ ]
768
+ ) } , reject);`,
769
+ "oldTags.push(oldTag);" ,
770
+ "newTags.push(tag);" ,
771
+ ]
772
+ ) } ));`,
773
+ ]
774
+ ) } );`,
775
+ ]
776
+ ) } `,
777
+ ] )
761
778
: "// no hmr" ,
762
779
] ) ;
763
780
}
@@ -818,9 +835,9 @@ class MiniCssExtractPlugin {
818
835
getChunkModules ( chunk , chunkGraph ) {
819
836
return typeof chunkGraph !== "undefined"
820
837
? chunkGraph . getOrderedChunkModulesIterable (
821
- chunk ,
822
- compareModulesByIdentifier
823
- )
838
+ chunk ,
839
+ compareModulesByIdentifier
840
+ )
824
841
: chunk . modulesIterable ;
825
842
}
826
843
@@ -944,7 +961,7 @@ class MiniCssExtractPlugin {
944
961
` * ${ m . readableIdentifier ( requestShortener ) } ` ,
945
962
` - couldn't fulfill desired order of chunk group(s) ${ failedChunkGroups } ` ,
946
963
goodChunkGroups &&
947
- ` - while fulfilling desired order of chunk group(s) ${ goodChunkGroups } ` ,
964
+ ` - while fulfilling desired order of chunk group(s) ${ goodChunkGroups } ` ,
948
965
]
949
966
. filter ( Boolean )
950
967
. join ( "\n" ) ;
0 commit comments