Skip to content

Commit 0cba512

Browse files
authored
fix: fix several bugs in the PWA plugin UI, make it usable again (#4974)
closes #4903
1 parent 1594327 commit 0cba512

File tree

1 file changed

+43
-25
lines changed
  • packages/@vue/cli-plugin-pwa

1 file changed

+43
-25
lines changed

packages/@vue/cli-plugin-pwa/ui.js

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ module.exports = api => {
1515
json: ['public/manifest.json']
1616
}
1717
},
18-
onRead: ({ data, cwd }) => {
18+
onRead: ({ data }) => {
19+
// Dirty hack here: only in onRead can we delete files from the original data.
20+
// Remove (or, don't create the file) manifest.json if no actual content in it.
21+
if (!data.manifest || !Object.keys(data.manifest).length) {
22+
delete data.manifest
23+
}
24+
1925
return {
2026
prompts: [
2127
{
@@ -58,7 +64,12 @@ module.exports = api => {
5864
message: 'org.vue.pwa.config.pwa.backgroundColor.message',
5965
description: 'org.vue.pwa.config.pwa.backgroundColor.description',
6066
default: '#000000',
61-
value: data.manifest && data.manifest.background_color,
67+
value:
68+
(data.vue &&
69+
data.vue.pwa &&
70+
data.vue.pwa.manifestOptions &&
71+
data.vue.pwa.manifestOptions.background_color) ||
72+
(data.manifest && data.manifest.background_color),
6273
skipSave: true
6374
},
6475
{
@@ -82,12 +93,12 @@ module.exports = api => {
8293
type: 'list',
8394
message: 'org.vue.pwa.config.pwa.manifestCrossorigin.message',
8495
description: 'org.vue.pwa.config.pwa.manifestCrossorigin.description',
85-
default: undefined,
96+
default: null,
8697
value: data.vue && data.vue.pwa && data.vue.pwa.manifestCrossorigin,
8798
choices: [
8899
{
89100
name: 'none',
90-
value: undefined
101+
value: null
91102
},
92103
{
93104
name: 'anonymous',
@@ -102,35 +113,42 @@ module.exports = api => {
102113
]
103114
}
104115
},
105-
onWrite: async ({ onWriteApi, prompts, cwd }) => {
116+
onWrite: async ({ api: onWriteApi, data, prompts }) => {
106117
const result = {}
107118
for (const prompt of prompts.filter(p => !p.raw.skipSave)) {
108119
result[`pwa.${prompt.id}`] = await onWriteApi.getAnswer(prompt.id)
109120
}
110-
onWriteApi.setData('vue', result)
111-
112-
// Update app manifest
113121

114-
const name = result['name']
115-
if (name) {
116-
onWriteApi.setData('manifest', {
117-
name,
118-
short_name: name
119-
})
122+
const backgroundColor = await onWriteApi.getAnswer('backgroundColor')
123+
if (!data.manifest && backgroundColor) {
124+
result['pwa.manifestOptions.background_color'] = backgroundColor
120125
}
121126

122-
const themeColor = result['themeColor']
123-
if (themeColor) {
124-
onWriteApi.setData('manifest', {
125-
theme_color: themeColor
126-
})
127-
}
127+
onWriteApi.setData('vue', result)
128128

129-
const backgroundColor = await onWriteApi.getAnswer('backgroundColor')
130-
if (backgroundColor) {
131-
onWriteApi.setData('manifest', {
132-
background_color: backgroundColor
133-
})
129+
// Update app manifest (only when there's a manifest.json file,
130+
// otherwise it will be inferred from options in vue.config.js)
131+
if (data.manifest) {
132+
const name = result['name']
133+
if (name) {
134+
onWriteApi.setData('manifest', {
135+
name,
136+
short_name: name
137+
})
138+
}
139+
140+
const themeColor = result['themeColor']
141+
if (themeColor) {
142+
onWriteApi.setData('manifest', {
143+
theme_color: themeColor
144+
})
145+
}
146+
147+
if (backgroundColor) {
148+
onWriteApi.setData('manifest', {
149+
background_color: backgroundColor
150+
})
151+
}
134152
}
135153
}
136154
})

0 commit comments

Comments
 (0)