Skip to content

Commit

Permalink
fix: pwa-plugin avoid generating manifest when path is an URL (#5089)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkint authored and sodatea committed Jan 28, 2020
1 parent 02a0e8a commit b12574d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/@vue/cli-plugin-pwa/README.md
Expand Up @@ -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**

Expand Down
50 changes: 28 additions & 22 deletions packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js
Expand Up @@ -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)
})
}
}
}

Expand All @@ -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)
}

0 comments on commit b12574d

Please sign in to comment.