File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,10 +9,24 @@ import cssnano from 'cssnano'
99const WebpackRTLPlugin = function ( options = { filename : false , options : { } , plugins : [ ] } ) {
1010 this . options = options
1111 this . chunkHashs = { } ;
12+ this . pliginName = 'webpack-rtl-plugin' ;
1213}
1314
1415WebpackRTLPlugin . prototype . apply = function ( compiler ) {
15- compiler . plugin ( 'emit' , ( compilation , callback ) => {
16+ if ( this . options . options . updateRuntimeChunk ) {
17+ const rtlFlag = this . options . rtlFlag || 'IS_RTL' ;
18+ compiler . hooks . thisCompilation . tap ( this . pliginName , compilation => {
19+ compilation . mainTemplate . hooks . requireEnsure . tap ( this . pliginName , ( source , chunk , hash ) => {
20+ // already updated
21+ if ( source . indexOf ( '.rtl.css' ) !== - 1 ) {
22+ return source ;
23+ }
24+ return source . replace ( / ( v a r h r e f .* ) ( " \. c s s " ; ) / i, '$1 (' + rtlFlag + ' ? ".rtl.css" : ".css");' ) ;
25+ } ) ;
26+ } ) ;
27+ }
28+
29+ compiler . hooks . emit . tap ( this . pliginName , ( compilation ) => {
1630 const changedChunks = compilation . chunks . filter ( ( chunk ) => {
1731 const name = chunk . name || chunk . id ;
1832 const prevHash = this . chunkHashs [ name ] ;
@@ -79,7 +93,7 @@ WebpackRTLPlugin.prototype.apply = function(compiler) {
7993 chunk . files . push . apply ( chunk . files , rtlFiles )
8094 cb ( )
8195 } )
82- } , callback )
96+ } )
8397 } )
8498}
8599
You can’t perform that action at this time.
0 commit comments