@@ -75,35 +75,40 @@ module.exports = function chainDefault(api, vueConfig, options) {
7575 return webpackChain ;
7676 } ) ;
7777
78+ let isOnce = false ;
7879 // webpack 所有配置合入
79- return silentService ( service => {
80- // 注册插件
81- service . registerPlugin ( {
82- id : 'vue-cli-plugin:plugin-command-return-webpack-chain' ,
83- [ BUILT_IN ] : true ,
84- apply ( _api ) {
85- _api . registerCommand ( 'return-webpack-chain' , {
86- description : 'return config of webpack-chain.' ,
87- usage : 'micro-app return-webpack-chain' ,
88- } , ( ) => {
89- // global save vueConfig
90- _api . setState ( 'vueConfig' , vueConfig ) ;
91- // 覆盖逻辑
92- if ( api . resolveWebpackConfig ) {
93- const originaFn = api . resolveWebpackConfig ;
94- api . resolveWebpackConfig = function ( chainableConfig ) {
95- const finalWebpackChainConfig = api . resolveChainableWebpackConfig ( chainableConfig ) ;
96- const webpackConfig = originaFn ( finalWebpackChainConfig ) ;
97- const finalWebpackConfig = api . applyPluginHooks ( 'modifyWebpackConfig' , webpackConfig ) ;
98- api . setState ( 'webpackConfig' , finalWebpackConfig ) ;
99- return finalWebpackConfig ;
100- } ;
101- }
102- } ) ;
103- } ,
104- } ) ;
80+ api . chainWebpack ( webpackChain => {
81+ return silentService ( service => {
82+ // 注册插件
83+ service . registerPlugin ( {
84+ id : 'vue-cli-plugin:plugin-command-return-webpack-chain' ,
85+ [ BUILT_IN ] : true ,
86+ apply ( _api ) {
87+ _api . registerCommand ( 'return-webpack-chain' , {
88+ description : 'return config of webpack-chain.' ,
89+ usage : 'micro-app return-webpack-chain' ,
90+ } , ( ) => {
91+ // global save vueConfig
92+ _api . setState ( 'vueConfig' , vueConfig ) ;
93+ _api . resolveChainableWebpackConfig ( webpackChain ) ;
10594
106- // 同步扩充 webpack-chain config
107- return service . runSync ( 'return-webpack-chain' ) ;
95+ if ( ! isOnce ) {
96+ isOnce = true ;
97+ // 覆盖逻辑
98+ const originaFn = api . service . resolveWebpackConfig ;
99+ api . service . resolveWebpackConfig = function ( chainableConfig ) {
100+ const webpackConfig = originaFn . apply ( api . service , chainableConfig ) ;
101+ const finalWebpackConfig = _api . applyPluginHooks ( 'modifyWebpackConfig' , webpackConfig ) ;
102+ _api . setState ( 'webpackConfig' , finalWebpackConfig ) ;
103+ return finalWebpackConfig ;
104+ } ;
105+ }
106+ } ) ;
107+ } ,
108+ } ) ;
109+
110+ // 同步扩充 webpack-chain config
111+ return service . runSync ( 'return-webpack-chain' ) ;
112+ } ) ;
108113 } ) ;
109114} ;
0 commit comments