Skip to content

Commit dbf7231

Browse files
author
Guillaume Chau
committed
feat(ui): modern build mode
1 parent 9f5dda4 commit dbf7231

File tree

8 files changed

+161
-53
lines changed

8 files changed

+161
-53
lines changed

packages/@vue/cli-service/lib/commands/build/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ module.exports = (api, options) => {
4848
process.env.VUE_CLI_MODERN_MODE = true
4949
delete process.env.VUE_CLI_MODERN_BUILD
5050
await build(Object.assign({}, args, {
51-
modernBuild: false
51+
modernBuild: false,
52+
keepAlive: true
5253
}), api, options)
5354

5455
process.env.VUE_CLI_MODERN_BUILD = true
@@ -158,7 +159,9 @@ async function build (args, api, options) {
158159
const DashboardPlugin = require('../../webpack/DashboardPlugin')
159160
modifyConfig(webpackConfig, config => {
160161
config.plugins.push(new DashboardPlugin({
161-
type: 'build'
162+
type: 'build',
163+
modernBuild: args.modernBuild,
164+
keepAlive: args.keepAlive
162165
}))
163166
})
164167
}

packages/@vue/cli-service/lib/webpack/DashboardPlugin.js

+25-13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'use strict'
66

77
const path = require('path')
8+
const fs = require('fs-extra')
89
const webpack = require('webpack')
910
const { IpcMessenger } = require('@vue/cli-shared-utils')
1011
const { analyzeBundle } = require('./analyzeBundle')
@@ -32,12 +33,16 @@ function getTimeMessage (timer) {
3233
class DashboardPlugin {
3334
constructor (options) {
3435
this.type = options.type
36+
if (this.type === 'build' && options.modernBuild) {
37+
this.type = 'build-modern'
38+
}
3539
this.watching = false
40+
this.autoDisconnect = !options.keepAlive
3641
}
3742

3843
cleanup () {
3944
this.sendData = null
40-
ipc.disconnect()
45+
if (this.autoDisconnect) ipc.disconnect()
4146
}
4247

4348
apply (compiler) {
@@ -61,7 +66,7 @@ class DashboardPlugin {
6166
const progressPlugin = new webpack.ProgressPlugin((percent, msg) => {
6267
// Debouncing
6368
const time = Date.now()
64-
if (time - progressTime > 100) {
69+
if (time - progressTime > 300) {
6570
progressTime = time
6671
sendData([
6772
{
@@ -168,20 +173,27 @@ class DashboardPlugin {
168173
{
169174
type: 'operations',
170175
value: `idle${getTimeMessage(timer)}`
171-
},
172-
{
173-
type: 'stats',
174-
value: {
175-
errors: hasErrors,
176-
warnings: stats.hasWarnings(),
177-
data: statsData
178-
}
179176
}
180177
])
181178

182-
if (!this.watching) {
183-
this.cleanup()
184-
}
179+
const statsFile = path.resolve(process.cwd(), `.stats-${this.type}.json`)
180+
fs.writeJson(statsFile, {
181+
errors: hasErrors,
182+
warnings: stats.hasWarnings(),
183+
data: statsData
184+
}).then(() => {
185+
sendData([
186+
{
187+
type: 'stats'
188+
}
189+
])
190+
191+
if (!this.watching) {
192+
this.cleanup()
193+
}
194+
}).catch(error => {
195+
console.error(error)
196+
})
185197
})
186198
}
187199
}

packages/@vue/cli-ui-addon-webpack/src/components/WebpackAnalyzer.vue

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
<VueIcon icon="donut_large"/>
55
<div class="title">{{ $t('vue-webpack.analyzer.title') }}</div>
66

7+
<VueSwitch
8+
v-if="modernMode"
9+
v-model="showModernBuild"
10+
>
11+
{{ $t('vue-webpack.modern-mode') }}
12+
</VueSwitch>
13+
714
<template v-if="currentTree">
815
<VueButton
916
icon-left="arrow_upward"
@@ -22,6 +29,7 @@
2229
class="separator"
2330
/>
2431
</template>
32+
2533
<VueSelect
2634
v-model="selectedChunk"
2735
:disabled="Object.keys(modulesTrees).length === 0"
@@ -33,11 +41,13 @@
3341
:label="`${$t('vue-webpack.analyzer.chunk')} ${getChunkName(key)}`"
3442
/>
3543
</VueSelect>
44+
3645
<VueSelect v-model="sizeField">
3746
<VueSelectButton value="stats" :label="`${$t('vue-webpack.sizes.stats')}`"/>
3847
<VueSelectButton value="parsed" :label="`${$t('vue-webpack.sizes.parsed')}`"/>
3948
<VueSelectButton value="gzip" :label="`${$t('vue-webpack.sizes.gzip')}`"/>
4049
</VueSelect>
50+
4151
<VueButton
4252
class="icon-button"
4353
icon-left="help"

packages/@vue/cli-ui-addon-webpack/src/components/WebpackDashboard.vue

+9-6
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,20 @@
1919
class="separator"
2020
/>
2121
</template>
22+
23+
<VueSwitch
24+
v-if="modernMode"
25+
v-model="showModernBuild"
26+
>
27+
{{ $t('vue-webpack.modern-mode') }}
28+
</VueSwitch>
29+
2230
<VueSelect v-model="sizeField">
2331
<VueSelectButton value="stats" :label="`${$t('vue-webpack.sizes.stats')}`"/>
2432
<VueSelectButton value="parsed" :label="`${$t('vue-webpack.sizes.parsed')}`"/>
2533
<VueSelectButton value="gzip" :label="`${$t('vue-webpack.sizes.gzip')}`"/>
2634
</VueSelect>
35+
2736
<VueButton
2837
class="icon-button"
2938
icon-left="help"
@@ -67,12 +76,6 @@ export default {
6776
SpeedStats,
6877
AssetList,
6978
ModuleList
70-
},
71-
72-
sharedData () {
73-
return {
74-
serveUrl: `webpack-dashboard-serve-url`
75-
}
7679
}
7780
}
7881
</script>

packages/@vue/cli-ui-addon-webpack/src/mixins/Dashboard.js

+35-5
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,51 @@ export default {
1414
}
1515
},
1616

17+
sharedData () {
18+
return {
19+
serveUrl: `webpack-dashboard-serve-url`,
20+
modernMode: `webpack-dashboard-modern-mode`
21+
}
22+
},
23+
1724
computed: {
1825
sizeField: {
1926
get () { return this.$store.getters.sizeField },
2027
set (value) { this.$store.commit('sizeField', value) }
28+
},
29+
30+
showModernBuild: {
31+
get () { return this.$store.state.showModernBuild },
32+
set (value) { this.$store.commit('showModernBuild', value) }
33+
}
34+
},
35+
36+
watch: {
37+
modernMode: {
38+
handler (value) {
39+
this.showModernBuild = value
40+
},
41+
immediate: true
2142
}
2243
},
2344

2445
created () {
2546
const mode = this.mode = this.TaskDetails.task.command.indexOf('vue-cli-service serve') !== -1 ? 'serve' : 'build'
2647
this.$store.commit('mode', mode)
27-
this.$watchSharedData(`webpack-dashboard-${mode}-stats`, value => {
28-
this.$store.commit('stats', {
29-
mode,
30-
value
48+
if (mode === 'build') {
49+
this.syncMode('build-modern')
50+
}
51+
this.syncMode(mode)
52+
},
53+
54+
methods: {
55+
syncMode (mode) {
56+
this.$watchSharedData(`webpack-dashboard-${mode}-stats`, value => {
57+
this.$store.commit('stats', {
58+
mode,
59+
value
60+
})
3161
})
32-
})
62+
}
3363
}
3464
}

packages/@vue/cli-ui-addon-webpack/src/store/index.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,28 @@ const store = new Vuex.Store({
1010
return {
1111
sizeField: localStorage.getItem('vue-webpack.sizeField') || 'parsed',
1212
mode: 'serve',
13+
showModernBuild: true,
1314
serve: {
1415
stats: null
1516
},
1617
build: {
1718
stats: null
19+
},
20+
'build-modern': {
21+
stats: null
1822
}
1923
}
2024
},
2125

2226
getters: {
2327
sizeField: state => state.sizeField,
24-
mode: state => state.mode,
25-
stats: state => state[state.mode].stats,
28+
mode: state => {
29+
if (state.mode === 'build' && state.showModernBuild) {
30+
return 'build-modern'
31+
}
32+
return state.mode
33+
},
34+
stats: (state, getters) => state[getters.mode].stats,
2635
errors: (state, getters) => (getters.stats && getters.stats.data.errors) || [],
2736
warnings: (state, getters) => (getters.stats && getters.stats.data.warnings) || [],
2837
assets: (state, getters) => (getters.stats && getters.stats.data.assets) || [],
@@ -47,6 +56,10 @@ const store = new Vuex.Store({
4756
state.mode = value
4857
},
4958

59+
showModernBuild (state, value) {
60+
state.showModernBuild = value
61+
},
62+
5063
stats (state, { mode, value }) {
5164
state[mode].stats = value
5265
}

packages/@vue/cli-ui/locales/en.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@
410410
"gzip": "Gzip",
411411
"help": "<b>Stats:</b> size from webpack stats data.<br><b>Parsed:</b> size from extracted source (after minification plugins). More accurate.<br><b>Gzip:</b> size of gzipped extracted source."
412412
},
413+
"modern-mode": "Show modern build",
413414
"tasks": {
414415
"serve": {
415416
"description": "Compiles and hot-reloads for development",
@@ -431,7 +432,11 @@
431432
"wc-async": "Async web component"
432433
},
433434
"name": "Name for library or web-component mode (default: 'name' in package.json or entry filename)",
434-
"watch": "Watch for changes"
435+
"watch": "Watch for changes",
436+
"modern": {
437+
"label": "Modern mode",
438+
"description": "Build app targeting modern browsers with auto fallback"
439+
}
435440
},
436441
"inspect": {
437442
"description": "Inspect the resolved webpack config",

0 commit comments

Comments
 (0)