Skip to content

Commit 657e425

Browse files
author
Guillaume Chau
committed
feat(ui): restore webpack stats when switching projects
1 parent eca54fc commit 657e425

File tree

1 file changed

+38
-9
lines changed
  • packages/@vue/cli-ui/ui-defaults

1 file changed

+38
-9
lines changed

packages/@vue/cli-ui/ui-defaults/tasks.js

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,48 @@ const path = require('path')
22
const fs = require('fs-extra')
33

44
module.exports = api => {
5-
const { setSharedData, removeSharedData } = api.namespace('webpack-dashboard-')
5+
const { getSharedData, setSharedData, removeSharedData, watchSharedData } = api.namespace('webpack-dashboard-')
66

77
let firstRun = true
88
let hadFailed = false
99
let modernMode = false
1010

11-
function resetSharedData (key) {
12-
setSharedData(`${key}-status`, null)
13-
setSharedData(`${key}-progress`, 0)
14-
setSharedData(`${key}-operations`, null)
15-
setSharedData(`${key}-stats`, null)
16-
setSharedData(`${key}-sizes`, null)
17-
setSharedData(`${key}-problems`, null)
11+
const fields = {
12+
status: null,
13+
progress: 0,
14+
operations: null,
15+
stats: null,
16+
sizes: null,
17+
problems: null,
18+
url: null
19+
}
20+
function setupSharedData (mode) {
21+
resetSharedData(mode)
22+
for (const field in fields) {
23+
const id = `${mode}-${field}`
24+
watchSharedData(id, (value) => {
25+
const project = api.getProject()
26+
if (project) {
27+
setSharedData(`${project.id}-${id}`, value)
28+
}
29+
})
30+
}
31+
}
32+
33+
function resetSharedData (mode) {
34+
for (const field in fields) {
35+
const id = `${mode}-${field}`
36+
setSharedData(id, getSharedDataInitialValue(id, field))
37+
}
38+
}
39+
40+
function getSharedDataInitialValue (id, field) {
41+
const project = api.getProject()
42+
if (project) {
43+
const data = getSharedData(`${project.id}-${id}`)
44+
if (data != null) return data.value
45+
}
46+
return fields[field]
1847
}
1948

2049
async function onWebpackMessage ({ data: message }) {
@@ -73,7 +102,7 @@ module.exports = api => {
73102
// Init data
74103
api.onProjectOpen(() => {
75104
for (const key of ['serve', 'build', 'build-modern']) {
76-
resetSharedData(key)
105+
setupSharedData(key)
77106
}
78107
})
79108

0 commit comments

Comments
 (0)