@@ -592,28 +592,30 @@ class WebpackBaseBuilder extends Config {
592592 return { loader, options } ;
593593 }
594594
595- createBabelLoader ( ) {
596- const loaderName = 'babel-loader' ;
597- const babelOptions = { } ;
595+ createBabelLoader ( babel = { } ) {
596+ babel = this . merge ( { loader : 'babel-loader' , options : { } } , babel ) ;
598597 const babelEnv = process . env . BABEL_ENV ;
599598 if ( babelEnv ) {
600599 if ( this . isBabel7 ) { // @babel /core use envName key
601- babelOptions . envName = babelEnv ;
600+ babel . options . envName = babelEnv ;
602601 } else { // babel-core use forceEnv key
603- babelOptions . forceEnv = babelEnv ;
602+ babel . options . forceEnv = babelEnv ;
604603 }
605604 }
606605 const compile = this . config . compile || { } ;
607- const configCacheOptions = this . utils . isObject ( compile . cache ) ? compile . cache : { } ;
608- const cacheOptions = this . merge ( babelOptions , configCacheOptions ) ;
609- const config = compile . cache ? this . createCacheLoader ( cacheOptions , loaderName ) : { loader : loaderName , babelOptions } ;
606+ // use babel cache
607+ if ( compile . cache ) {
608+ const cacheOptions = this . utils . isBoolean ( compile . cache ) ? { } : compile . cache ;
609+ const cacheDirectory = this . utils . getCacheLoaderInfoPath ( babel . loader , this . env , this . type ) ;
610+ babel . options = this . merge ( babel . options , { cacheDirectory } , cacheOptions ) ;
611+ }
610612 // use project .babelrc
611613 if ( fs . existsSync ( this . projectBabelrc ) ) {
612- return config ;
614+ return babel ;
613615 }
614616 // use default babelrc
615- const options = this . merge ( babelOptions , this . babelConfig ) ;
616- return this . merge ( config , { options } ) ;
617+ babel . options = this . merge ( babel . options , this . babelConfig ) ;
618+ return babel ;
617619 }
618620
619621 createCacheLoader ( loaderOptions , name ) {
0 commit comments