@@ -53,6 +53,42 @@ export default function configure(options) {
5353
5454 webpackConfig = webpackConfig || { } ;
5555
56+ let loaders = [ ] . concat ( delve ( webpackConfig , 'module.loaders' ) || [ ] , delve ( webpackConfig , 'module.rules' ) || [ ] ) ;
57+
58+ function evaluateCondition ( condition , filename , expected ) {
59+ if ( typeof condition === 'function' ) {
60+ return condition ( filename ) == expected ;
61+ }
62+ else if ( condition instanceof RegExp ) {
63+ return condition . test ( filename ) == expected ;
64+ }
65+ if ( Array . isArray ( condition ) ) {
66+ for ( let i = 0 ; i < condition . length ; i ++ ) {
67+ if ( evaluateCondition ( condition [ i ] , filename ) ) return expected ;
68+ }
69+ }
70+ return ! expected ;
71+ }
72+
73+ function getLoader ( predicate ) {
74+ if ( typeof predicate === 'string' ) {
75+ let filename = predicate ;
76+ predicate = loader => {
77+ let { test, include, exclude } = loader ;
78+ if ( exclude && evaluateCondition ( exclude , filename , false ) ) return false ;
79+ if ( include && ! evaluateCondition ( include , filename , true ) ) return false ;
80+ if ( test && evaluateCondition ( test , filename , true ) ) return true ;
81+ return false ;
82+ } ;
83+ }
84+ for ( let i = 0 ; i < loaders . length ; i ++ ) {
85+ if ( predicate ( loaders [ i ] ) ) {
86+ return { index : i , loader : loaders [ i ] } ;
87+ }
88+ }
89+ return false ;
90+ }
91+
5692 function webpackProp ( name , value ) {
5793 let configured = delve ( webpackConfig , 'resolve.alias' ) ;
5894 if ( Array . isArray ( value ) ) {
@@ -111,10 +147,10 @@ export default function configure(options) {
111147 webpack : {
112148 devtool : 'cheap-module-eval-source-map' ,
113149 module : {
114- loaders : [
115- babelLoader ( options ) ,
116- cssLoader ( options )
117- ]
150+ loaders : loaders . concat (
151+ ! getLoader ( rule => ` ${ rule . use } , ${ rule . loader } ` . match ( / \b b a b e l - l o a d e r \b / ) ) && babelLoader ( options ) ,
152+ ! getLoader ( 'foo.css' ) && cssLoader ( options )
153+ ) . filter ( Boolean )
118154 } ,
119155 resolve : webpackProp ( 'resolve' , {
120156 modules : webpackProp ( 'resolve.modules' , [
0 commit comments