@@ -2,8 +2,8 @@ import type webpack from 'webpack'
22
33type LoaderTest = ( l : { path : string ; ident ?: string } ) => boolean
44
5- const templatePitcherTest : LoaderTest = l => / ( \/ | \\ | @ ) w i n d i c s s - t e m p l a t e / . test ( l . path )
6- const windiPitcherTest : LoaderTest = l => / ( \/ | \\ | @ ) w i n d i c s s - s t y l e - p i t c h e r / . test ( l . path )
5+ const windiTemplateTest : LoaderTest = l => / ( \/ | \\ | @ ) w i n d i c s s - t e m p l a t e / . test ( l . path )
6+ const windiStylePitcherTest : LoaderTest = l => / ( \/ | \\ | @ ) w i n d i c s s - s t y l e - p i t c h e r / . test ( l . path )
77const postCssLoaderTest : LoaderTest = l => / ( \/ | \\ | @ ) p o s t c s s - l o a d e r / . test ( l . path )
88const cssLoaderTest : LoaderTest = l => / ( \/ | \\ | @ ) c s s - l o a d e r / . test ( l . path )
99
@@ -13,27 +13,32 @@ const cssLoaderTest: LoaderTest = l => /(\/|\\|@)css-loader/.test(l.path)
1313 * We move it just after the PostCSS loader
1414 */
1515export const pitch = function ( this : webpack . loader . LoaderContext , remainingRequest : string ) {
16- const findLoaderIndex = ( test : LoaderTest ) => this . loaders . findIndex ( test )
17- /**
18- * Removes a loader recursively from the request and returns a found instance
19- * @param test
20- */
21- const removeLoader : ( test : LoaderTest ) => any = ( test ) => {
16+ const findLoaderIndex = ( test : LoaderTest ) => this . loaders . findIndex ( ( loader ) => {
17+ return test ( loader ) && ! loader . normalExecuted
18+ } )
19+
20+ const markLoaderAsExecuted : ( test : LoaderTest ) => any = ( test ) => {
2221 let index , loader
2322 while ( ( index = findLoaderIndex ( test ) ) !== - 1 ) {
2423 loader = this . loaders [ index ]
25- this . loaders . splice ( index , 1 )
24+ /*
25+ * Hacky solution to avoid the loader from running.
26+ * Previously we removed the loader entirely however, this caused
27+ * a conflict with other loaders (see https://github.com/windicss/windicss-webpack-plugin/issues/111).
28+ */
29+ loader . pitchExecuted = true
30+ loader . normalExecuted = true
2631 }
2732 return loader
2833 }
2934
3035 // remove the pitcher immediately
31- removeLoader ( windiPitcherTest )
36+ markLoaderAsExecuted ( windiStylePitcherTest )
3237
3338 // make sure we're dealing with style-loader
3439 if ( ! remainingRequest . includes ( '&type=style' ) ) {
3540 // clean up
36- removeLoader ( templatePitcherTest )
41+ markLoaderAsExecuted ( windiTemplateTest )
3742 return
3843 }
3944
@@ -45,11 +50,11 @@ export const pitch = function(this: webpack.loader.LoaderContext, remainingReque
4550 // we couldn't find either PostCSS loader or CSS loader so we bail out
4651 if ( newTemplateLoaderIndex === - 1 ) {
4752 // clean up
48- removeLoader ( templatePitcherTest )
53+ markLoaderAsExecuted ( windiTemplateTest )
4954 return
5055 }
5156
52- const templateLoader = removeLoader ( templatePitcherTest )
57+ const templateLoader = markLoaderAsExecuted ( windiTemplateTest )
5358 // re-insert the template-loader in the right spot
5459 if ( templateLoader )
5560 this . loaders . splice ( newTemplateLoaderIndex + 1 , 0 , templateLoader )
0 commit comments