@@ -285,7 +285,7 @@ class WebpackBaseBuilder extends Config {
285285 if ( this . entryLoader ) {
286286 const mergeLoader = this . merge ( entryLoader , this . entryLoader ) ;
287287 const entryLoaderOptions = mergeLoader . options || mergeLoader ;
288- const { match, loader, babel = 'babel-loader' } = entryLoaderOptions ;
288+ const { match, loader } = entryLoaderOptions ;
289289 let templateFile = entryLoaderOptions . templateFile || '' ;
290290 // 零配置:设置默认 entry 模板代码路径配置, TODO entry exclude 实现
291291 if ( templateFile ) {
@@ -299,14 +299,17 @@ class WebpackBaseBuilder extends Config {
299299 }
300300
301301 if ( match && loader ) {
302+ const babel = this . createBabelLoader ( ) ;
303+ const babelOptions = this . merge ( babel . options , { babelrc : this . babelrc } ) ;
304+ const babelLoaderString = `${ babel . loader } ?${ JSON . stringify ( babelOptions ) } ` ;
302305 const entryLoaderString = this . utils . getLoaderOptionString ( loader , { templateFile } ) ;
303306 const regMatch = match instanceof RegExp ? match : new RegExp ( match ) ;
304307 Object . keys ( entries ) . forEach ( entryName => {
305308 const entryFile = entries [ entryName ] ;
306309 if ( this . utils . isString ( entryFile ) ) {
307310 const fileExt = path . extname ( entryFile ) ;
308311 if ( regMatch . test ( fileExt ) ) {
309- entries [ entryName ] = [ babel , entryLoaderString , entryFile ] . join ( '!' ) ;
312+ entries [ entryName ] = [ babelLoaderString , entryLoaderString , entryFile ] . join ( '!' ) ;
310313 }
311314 }
312315 } ) ;
@@ -592,8 +595,7 @@ class WebpackBaseBuilder extends Config {
592595 return config ;
593596 }
594597 // use default babelrc
595- const options = require ( this . babelrc ) ;
596- return this . merge ( config , { options } ) ;
598+ return this . merge ( config , { options : this . babelConfig } ) ;
597599 }
598600
599601 createCacheLoader ( loaderOptions , name ) {
@@ -658,8 +660,8 @@ class WebpackBaseBuilder extends Config {
658660 setBabelENV ( value ) {
659661 const key = value || this . webpackConfig . target ;
660662 try {
661- const json = require ( this . babelrc ) ;
662- if ( json && json . env && json . env [ key ] ) {
663+ const { env } = this . babelConfig ;
664+ if ( env && env [ key ] ) {
663665 process . env . BABEL_ENV = key ;
664666 }
665667 } catch ( e ) {
0 commit comments