Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pwa-plugin avoid generating manifest when path is an URL #5089

Merged
merged 1 commit into from Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
sodatea marked this conversation as resolved.
Show resolved Hide resolved
}