Skip to content

manifest link can use relative path #5984

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/core-plugins/pwa.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ file, or the `"vue"` field in `package.json`.

This option is used if you need to add a version to your icons and manifest, against browser’s cache. This will append `?v=<pwa.assetsVersion>` to the URLs of the icons and manifest.

- **pwa.manifestUseRelative**

- Default: `false`

Enable use a relative path on `<link rel="manifest" />` . This value will be replaced by **publicPath** when it false.

By this way, you can set a relative path for `start_url` in `manifest.json`


- **pwa.manifestPath**

- Default: `'manifest.json'`
Expand Down
11 changes: 8 additions & 3 deletions packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const defaults = {
appleMobileWebAppCapable: 'no',
appleMobileWebAppStatusBarStyle: 'default',
assetsVersion: '',
manifestUseRelative: false,
manifestPath: 'manifest.json',
manifestOptions: {},
manifestCrossorigin: undefined
Expand Down Expand Up @@ -73,6 +74,7 @@ module.exports = class HtmlPwaPlugin {
appleMobileWebAppCapable,
appleMobileWebAppStatusBarStyle,
assetsVersion,
manifestUseRelative,
manifestPath,
iconPaths,
manifestCrossorigin
Expand Down Expand Up @@ -104,12 +106,12 @@ module.exports = class HtmlPwaPlugin {
makeTag('link', manifestCrossorigin
? {
rel: 'manifest',
href: getTagHref(publicPath, manifestPath, assetsVersionStr),
href: getTagHref(publicPath, manifestPath, assetsVersionStr, manifestUseRelative),
crossorigin: manifestCrossorigin
}
: {
rel: 'manifest',
href: getTagHref(publicPath, manifestPath, assetsVersionStr)
href: getTagHref(publicPath, manifestPath, assetsVersionStr, manifestUseRelative)
}
)
)
Expand Down Expand Up @@ -206,8 +208,11 @@ function makeTag (tagName, attributes, closeTag = false) {
}
}

function getTagHref (publicPath, href, assetsVersionStr) {
function getTagHref (publicPath, href, assetsVersionStr, useRelativePath) {
let tagHref = `${href}${assetsVersionStr}`
if (useRelativePath) {
return tagHref
}
if (!isHrefAbsoluteUrl(href)) {
tagHref = `${publicPath}${tagHref}`
}
Expand Down