diff --git a/packages/@vue/cli-plugin-pwa/README.md b/packages/@vue/cli-plugin-pwa/README.md index abf24578b9..8bc16b7eeb 100644 --- a/packages/@vue/cli-plugin-pwa/README.md +++ b/packages/@vue/cli-plugin-pwa/README.md @@ -69,7 +69,7 @@ file, or the `"vue"` field in `package.json`. - Default: `'manifest.json'` - The path of app’s manifest. + 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. - **pwa.manifestOptions** diff --git a/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js b/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js index 6ff0003842..462a78af06 100644 --- a/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js +++ b/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js @@ -151,27 +151,29 @@ module.exports = class HtmlPwaPlugin { }) }) - compiler.hooks.emit.tapAsync(ID, (data, cb) => { - const { - name, - themeColor, - manifestPath, - manifestOptions - } = this.options - const publicOptions = { - name, - short_name: name, - theme_color: themeColor - } - const outputManifest = JSON.stringify( - Object.assign(publicOptions, defaultManifest, manifestOptions) - ) - data.assets[manifestPath] = { - source: () => outputManifest, - size: () => outputManifest.length - } - cb(null, data) - }) + if (!isHrefAbsoluteUrl(this.options.manifestPath)) { + compiler.hooks.emit.tapAsync(ID, (data, cb) => { + const { + name, + themeColor, + manifestPath, + manifestOptions + } = this.options + const publicOptions = { + name, + short_name: name, + theme_color: themeColor + } + const outputManifest = JSON.stringify( + Object.assign(publicOptions, defaultManifest, manifestOptions) + ) + data.assets[manifestPath] = { + source: () => outputManifest, + size: () => outputManifest.length + } + cb(null, data) + }) + } } } @@ -185,8 +187,12 @@ function makeTag (tagName, attributes, closeTag = false) { function getTagHref (publicPath, href, assetsVersionStr) { let tagHref = `${href}${assetsVersionStr}` - if (!(/(http(s?)):\/\//gi.test(href))) { + if (!isHrefAbsoluteUrl(href)) { tagHref = `${publicPath}${tagHref}` } return tagHref } + +function isHrefAbsoluteUrl (href) { + return /(http(s?)):\/\//gi.test(href) +}