diff --git a/docs/core-plugins/pwa.md b/docs/core-plugins/pwa.md index 4457c4357e..b4d195f2f9 100644 --- a/docs/core-plugins/pwa.md +++ b/docs/core-plugins/pwa.md @@ -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=` to the URLs of the icons and manifest. +- **pwa.manifestUseRelative** + + - Default: `false` + + Enable use a relative path on `` . 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'` diff --git a/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js b/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js index f6683ef47e..05a10beba8 100644 --- a/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js +++ b/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js @@ -7,6 +7,7 @@ const defaults = { appleMobileWebAppCapable: 'no', appleMobileWebAppStatusBarStyle: 'default', assetsVersion: '', + manifestUseRelative: false, manifestPath: 'manifest.json', manifestOptions: {}, manifestCrossorigin: undefined @@ -73,6 +74,7 @@ module.exports = class HtmlPwaPlugin { appleMobileWebAppCapable, appleMobileWebAppStatusBarStyle, assetsVersion, + manifestUseRelative, manifestPath, iconPaths, manifestCrossorigin @@ -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) } ) ) @@ -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}` }