File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -591,6 +591,22 @@ class WebpackBaseBuilder extends Config {
591591 } ) ;
592592 }
593593 }
594+
595+ // 根据 BABEL_ENV 动态获取 BABEL 配置, 支持 node 和 web 配置
596+ setBabelENV ( value ) {
597+ const babelrc = path . join ( this . baseDir , '.babelrc' ) ;
598+ if ( fs . existsSync ( babelrc ) ) {
599+ const jsonStr = fs . readFileSync ( babelrc ) ;
600+ try {
601+ const json = JSON . parse ( jsonStr ) ;
602+ if ( json && json . env && json . env [ value ] ) {
603+ process . env . BABEL_ENV = value ;
604+ }
605+ } catch ( e ) {
606+ console . warn ( 'setBabelENV error' , e ) ;
607+ }
608+ }
609+ }
594610}
595611
596612module . exports = WebpackBaseBuilder ;
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ class WebpackClientBuilder extends WebpackBaseBuilder {
77 constructor ( config ) {
88 super ( config ) ;
99 this . type = WebpackClientBuilder . TYPE ;
10+ this . setBabelENV ( 'web' ) ;
1011 this . setDevTool ( config . devtool ) ;
1112 this . setPack ( config . packs ) ;
1213 this . setTarget ( WebpackClientBuilder . TARGET ) ;
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ class WebpackDllBuilder extends WebpackBaseBuilder {
1010 super ( merge ( { useHost : false , buildDll : true } , config ) ) ;
1111 this . dll = true ;
1212 this . type = WebpackDllBuilder . TYPE ;
13+ this . setBabelENV ( 'web' ) ;
1314 this . mergeConfig ( Config . dllConfig ) ;
1415 this . setBuildPath ( this . utils . getDllCompileFileDir ( this . env ) ) ;
1516 this . setDevTool ( config . devtool ) ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ class WebpackServerBuilder extends WebpackBaseBuilder {
88 super ( config ) ;
99 this . ssr = true ;
1010 this . type = WebpackServerBuilder . TYPE ;
11+ this . setBabelENV ( 'node' ) ;
1112 this . setTarget ( WebpackServerBuilder . TARGET ) ;
1213 this . setNode ( { __filename : false , __dirname : false } ) ;
1314 this . setLibraryTarget ( 'commonjs' ) ;
You can’t perform that action at this time.
0 commit comments