@@ -53,35 +53,43 @@ module.exports = (api, options) => {
53
53
}
54
54
55
55
process . env . VUE_CLI_BUILD_TARGET = args . target
56
- if ( args . module && args . target === 'app' ) {
57
- process . env . VUE_CLI_MODERN_MODE = true
58
- if ( ! process . env . VUE_CLI_MODERN_BUILD ) {
59
- // main-process for legacy build
60
- await build ( Object . assign ( { } , args , {
61
- modernBuild : false ,
62
- keepAlive : true
63
- } ) , api , options )
64
- // spawn sub-process of self for modern build
65
- const { execa } = require ( '@vue/cli-shared-utils' )
66
- const cliBin = require ( 'path' ) . resolve ( __dirname , '../../../bin/vue-cli-service.js' )
67
- await execa ( 'node' , [ cliBin , 'build' , ...rawArgs ] , {
68
- stdio : 'inherit' ,
69
- env : {
70
- VUE_CLI_MODERN_BUILD : true
71
- }
72
- } )
73
- } else {
74
- // sub-process for modern build
75
- await build ( Object . assign ( { } , args , {
76
- modernBuild : true ,
77
- clean : false
78
- } ) , api , options )
79
- }
80
- delete process . env . VUE_CLI_MODERN_MODE
81
- } else {
56
+
57
+ const { log, execa } = require ( '@vue/cli-shared-utils' )
58
+ const { allProjectTargetsSupportModule } = require ( '../../util/targets' )
59
+
60
+ let needsDifferentialLoading = args . target === 'app' && args . module
61
+ if ( allProjectTargetsSupportModule ) {
62
+ log (
63
+ `All browser targets in the browserslist configuration have supported ES module.\n` +
64
+ `Therefore we don't build two separate bundles for differential loading.\n`
65
+ )
66
+ needsDifferentialLoading = false
67
+ }
68
+
69
+ if ( ! needsDifferentialLoading ) {
82
70
await build ( args , api , options )
71
+ return
72
+ }
73
+
74
+ process . env . VUE_CLI_MODERN_MODE = true
75
+ if ( ! process . env . VUE_CLI_MODERN_BUILD ) {
76
+ // main-process for legacy build
77
+ const legacyBuildArgs = { ...args , moduleBuild : false , keepAlive : true }
78
+ await build ( legacyBuildArgs , api , options )
79
+
80
+ // spawn sub-process of self for modern build
81
+ const cliBin = require ( 'path' ) . resolve ( __dirname , '../../../bin/vue-cli-service.js' )
82
+ await execa ( 'node' , [ cliBin , 'build' , ...rawArgs ] , {
83
+ stdio : 'inherit' ,
84
+ env : {
85
+ VUE_CLI_MODERN_BUILD : true
86
+ }
87
+ } )
88
+ } else {
89
+ // sub-process for modern build
90
+ const moduleBuildArgs = { ...args , moduleBuild : true , clean : false }
91
+ await build ( moduleBuildArgs , api , options )
83
92
}
84
- delete process . env . VUE_CLI_BUILD_TARGET
85
93
} )
86
94
}
87
95
@@ -104,8 +112,8 @@ async function build (args, api, options) {
104
112
const mode = api . service . mode
105
113
if ( args . target === 'app' ) {
106
114
const bundleTag = args . module
107
- ? args . modernBuild
108
- ? `modern bundle `
115
+ ? args . moduleBuild
116
+ ? `module bundle `
109
117
: `legacy bundle `
110
118
: ``
111
119
logWithSpinner ( `Building ${ bundleTag } for ${ mode } ...` )
@@ -125,7 +133,7 @@ async function build (args, api, options) {
125
133
}
126
134
127
135
const targetDir = api . resolve ( options . outputDir )
128
- const isLegacyBuild = args . target === 'app' && args . module && ! args . modernBuild
136
+ const isLegacyBuild = args . target === 'app' && args . module && ! args . moduleBuild
129
137
130
138
// resolve raw webpack config
131
139
let webpackConfig
@@ -162,7 +170,7 @@ async function build (args, api, options) {
162
170
modifyConfig ( webpackConfig , config => {
163
171
config . plugins . push ( new DashboardPlugin ( {
164
172
type : 'build' ,
165
- modernBuild : args . modernBuild ,
173
+ moduleBuild : args . moduleBuild ,
166
174
keepAlive : args . keepAlive
167
175
} ) )
168
176
} )
0 commit comments