@@ -579,6 +579,18 @@ class WebpackBaseBuilder extends Config {
579579 return { loader, options } ;
580580 }
581581
582+ createBabelLoader ( ) {
583+ const loaderName = 'babel-loader' ;
584+ const config = this . config . compile . cache ? this . createCacheLoader ( this . config . compile . cache , loaderName ) : { loader : loaderName , options : { } } ;
585+ // use project .babelrc
586+ if ( fs . existsSync ( this . projectBabelrc ) ) {
587+ return config ;
588+ }
589+ // use default .babelrc
590+ const options = this . utils . readFile ( this . babelrc ) ;
591+ return this . merge ( config , { options } ) ;
592+ }
593+
582594 createCacheLoader ( loaderOptions , name ) {
583595 const loader = name || 'cache-loader' ;
584596 const cacheDirectory = this . utils . getCacheLoaderInfoPath ( loader , this . env , this . type ) ;
@@ -588,7 +600,7 @@ class WebpackBaseBuilder extends Config {
588600
589601 createThreadLoader ( loaderOptions ) {
590602 const loader = 'thread-loader' ;
591- const options = this . utils . isObject ( loaderOptions ) ? this . merge ( { workers : 2 } , loaderOptions ) : { } ;
603+ const options = this . utils . isObject ( loaderOptions ) ? this . merge ( { workers : 2 } , loaderOptions ) : { } ;
592604 return { loader, options } ;
593605 }
594606
@@ -639,17 +651,14 @@ class WebpackBaseBuilder extends Config {
639651
640652 // 根据 BABEL_ENV 动态获取 BABEL 配置, 支持 node 和 web 配置
641653 setBabelENV ( value ) {
642- const babelrc = path . join ( this . baseDir , '.babelrc' ) ;
643- if ( fs . existsSync ( babelrc ) ) {
644- const jsonStr = fs . readFileSync ( babelrc ) ;
645- try {
646- const json = JSON . parse ( jsonStr ) ;
647- if ( json && json . env && json . env [ value ] ) {
648- process . env . BABEL_ENV = value ;
649- }
650- } catch ( e ) {
651- /* istanbul ignore next */
654+ const key = value || this . webpackConfig . target ;
655+ try {
656+ const json = this . utils . readFile ( this . babelrc ) ;
657+ if ( json && json . env && json . env [ key ] ) {
658+ process . env . BABEL_ENV = key ;
652659 }
660+ } catch ( e ) {
661+ /* istanbul ignore next */
653662 }
654663 }
655664}
0 commit comments