@@ -36,7 +36,7 @@ module.exports = (api, options) => {
3636 '--report-json' : 'generate report.json to help analyze bundle content' ,
3737 '--watch' : `watch for changes`
3838 }
39- } , async ( args ) => {
39+ } , async ( args , rawArgs ) => {
4040 for ( const key in defaults ) {
4141 if ( args [ key ] == null ) {
4242 args [ key ] = defaults [ key ]
@@ -50,20 +50,29 @@ module.exports = (api, options) => {
5050 process . env . VUE_CLI_BUILD_TARGET = args . target
5151 if ( args . modern && args . target === 'app' ) {
5252 process . env . VUE_CLI_MODERN_MODE = true
53- delete process . env . VUE_CLI_MODERN_BUILD
54- await build ( Object . assign ( { } , args , {
55- modernBuild : false ,
56- keepAlive : true
57- } ) , api , options )
58-
59- process . env . VUE_CLI_MODERN_BUILD = true
60- await build ( Object . assign ( { } , args , {
61- modernBuild : true ,
62- clean : false
63- } ) , api , options )
64-
53+ if ( ! process . env . VUE_CLI_MODERN_BUILD ) {
54+ // main-process for legacy build
55+ await build ( Object . assign ( { } , args , {
56+ modernBuild : false ,
57+ keepAlive : true
58+ } ) , api , options )
59+ // spawn sub-process of self for modern build
60+ const { execa } = require ( '@vue/cli-shared-utils' )
61+ const cliBin = api . resolve ( 'node_modules/.bin/vue-cli-service' )
62+ await execa ( cliBin , [ 'build' , ...rawArgs ] , {
63+ stdio : 'inherit' ,
64+ env : {
65+ VUE_CLI_MODERN_BUILD : true
66+ }
67+ } )
68+ } else {
69+ // sub-process for modern build
70+ await build ( Object . assign ( { } , args , {
71+ modernBuild : true ,
72+ clean : false
73+ } ) , api , options )
74+ }
6575 delete process . env . VUE_CLI_MODERN_MODE
66- delete process . env . VUE_CLI_MODERN_BUILD
6776 } else {
6877 if ( args . modern ) {
6978 const { warn } = require ( '@vue/cli-shared-utils' )
0 commit comments