@@ -29,13 +29,13 @@ function modify(baseConfig, configOptions, webpack, userOptions = {}) {
2929 }
3030
3131 // Safely locate Babel-Loader in Razzle's webpack internals
32- const babelLoaderIndex = config . module . rules . findIndex ( babelLoaderFinder ) ;
33- if ( babelLoaderIndex === - 1 ) {
34- throw new Error ( 'babel-loader was erased from config' ) ;
32+ const babelLoader = config . module . rules . find ( babelLoaderFinder ) ;
33+ if ( ! babelLoader ) {
34+ throw new Error (
35+ `'babel-loader' was erased from config, we need it to define 'include' option`
36+ ) ;
3537 }
3638
37- const babelLoader = config . module . rules [ babelLoaderIndex ] ;
38-
3939 // Get the correct `include` option, since that hasn't changed.
4040 // This tells Razzle which directories to transform.
4141 const { include } = babelLoader ;
@@ -45,12 +45,16 @@ function modify(baseConfig, configOptions, webpack, userOptions = {}) {
4545 include,
4646 enforce : 'pre' ,
4747 test : / \. t s x ? $ / ,
48- loader : require . resolve ( 'tslint-loader' ) ,
49- options : Object . assign (
50- { } ,
51- defaultOptions . tslintLoader ,
52- options . tslintLoader
53- ) ,
48+ use : [
49+ {
50+ loader : require . resolve ( 'tslint-loader' ) ,
51+ options : Object . assign (
52+ { } ,
53+ defaultOptions . tslintLoader ,
54+ options . tslintLoader
55+ ) ,
56+ } ,
57+ ] ,
5458 } ;
5559 config . module . rules . push ( tslintLoader ) ;
5660
@@ -70,13 +74,15 @@ function modify(baseConfig, configOptions, webpack, userOptions = {}) {
7074 // If using babel, also add babel-loader to ts files,
7175 // so we can use babel plugins on tsx files too
7276 tsLoader . use = [ babelLoader . use [ 1 ] , ...tsLoader . use ] ;
73-
74- config . module . rules . push ( tsLoader ) ;
7577 } else {
76- // If not using babel, override it with tsLoader
77- config . module . rules [ babelLoaderIndex ] = tsLoader ;
78+ // If not using babel, remove it
79+ config . module . rules = config . module . rules . filter (
80+ rule => ! babelLoaderFinder ( rule )
81+ ) ;
7882 }
7983
84+ config . module . rules . push ( tsLoader ) ;
85+
8086 return config ;
8187}
8288
0 commit comments