Skip to content

Commit fe18236

Browse files
tkintmactanxin
authored andcommitted
fix: pwa-plugin avoid generating manifest when path is an URL (vuejs#5089)
1 parent c508edb commit fe18236

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

packages/@vue/cli-plugin-pwa/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ file, or the `"vue"` field in `package.json`.
6969

7070
- Default: `'manifest.json'`
7171

72-
The path of app’s manifest.
72+
The path of app’s manifest. If the path is an URL, the plugin won't generate a manifest.json in the dist directory during the build.
7373

7474
- **pwa.manifestOptions**
7575

packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -151,27 +151,29 @@ module.exports = class HtmlPwaPlugin {
151151
})
152152
})
153153

154-
compiler.hooks.emit.tapAsync(ID, (data, cb) => {
155-
const {
156-
name,
157-
themeColor,
158-
manifestPath,
159-
manifestOptions
160-
} = this.options
161-
const publicOptions = {
162-
name,
163-
short_name: name,
164-
theme_color: themeColor
165-
}
166-
const outputManifest = JSON.stringify(
167-
Object.assign(publicOptions, defaultManifest, manifestOptions)
168-
)
169-
data.assets[manifestPath] = {
170-
source: () => outputManifest,
171-
size: () => outputManifest.length
172-
}
173-
cb(null, data)
174-
})
154+
if (!isHrefAbsoluteUrl(this.options.manifestPath)) {
155+
compiler.hooks.emit.tapAsync(ID, (data, cb) => {
156+
const {
157+
name,
158+
themeColor,
159+
manifestPath,
160+
manifestOptions
161+
} = this.options
162+
const publicOptions = {
163+
name,
164+
short_name: name,
165+
theme_color: themeColor
166+
}
167+
const outputManifest = JSON.stringify(
168+
Object.assign(publicOptions, defaultManifest, manifestOptions)
169+
)
170+
data.assets[manifestPath] = {
171+
source: () => outputManifest,
172+
size: () => outputManifest.length
173+
}
174+
cb(null, data)
175+
})
176+
}
175177
}
176178
}
177179

@@ -185,8 +187,12 @@ function makeTag (tagName, attributes, closeTag = false) {
185187

186188
function getTagHref (publicPath, href, assetsVersionStr) {
187189
let tagHref = `${href}${assetsVersionStr}`
188-
if (!(/(http(s?)):\/\//gi.test(href))) {
190+
if (!isHrefAbsoluteUrl(href)) {
189191
tagHref = `${publicPath}${tagHref}`
190192
}
191193
return tagHref
192194
}
195+
196+
function isHrefAbsoluteUrl (href) {
197+
return /(http(s?)):\/\//gi.test(href)
198+
}

0 commit comments

Comments
 (0)