Skip to content

Commit

Permalink
feat: allow use of full url for pwa manifest and icons (#4736)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkint authored and sodatea committed Nov 12, 2019
1 parent 1c41371 commit 6c4a0bf
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js
Expand Up @@ -75,25 +75,25 @@ module.exports = class HtmlPwaPlugin {
rel: 'icon',
type: 'image/png',
sizes: '32x32',
href: `${publicPath}${iconPaths.favicon32}${assetsVersionStr}`
href: getTagHref(publicPath, iconPaths.favicon32, assetsVersionStr)
}),
makeTag('link', {
rel: 'icon',
type: 'image/png',
sizes: '16x16',
href: `${publicPath}${iconPaths.favicon16}${assetsVersionStr}`
href: getTagHref(publicPath, iconPaths.favicon16, assetsVersionStr)
}),

// Add to home screen for Android and modern mobile browsers
makeTag('link', manifestCrossorigin
? {
rel: 'manifest',
href: `${publicPath}${manifestPath}${assetsVersionStr}`,
href: getTagHref(publicPath, manifestPath, assetsVersionStr),
crossorigin: manifestCrossorigin
}
: {
rel: 'manifest',
href: `${publicPath}${manifestPath}${assetsVersionStr}`
href: getTagHref(publicPath, manifestPath, assetsVersionStr)
}
),
makeTag('meta', {
Expand All @@ -116,18 +116,18 @@ module.exports = class HtmlPwaPlugin {
}),
makeTag('link', {
rel: 'apple-touch-icon',
href: `${publicPath}${iconPaths.appleTouchIcon}${assetsVersionStr}`
href: getTagHref(publicPath, iconPaths.appleTouchIcon, assetsVersionStr)
}),
makeTag('link', {
rel: 'mask-icon',
href: `${publicPath}${iconPaths.maskIcon}${assetsVersionStr}`,
href: getTagHref(publicPath, iconPaths.maskIcon, assetsVersionStr),
color: themeColor
}),

// Add to home screen for Windows
makeTag('meta', {
name: 'msapplication-TileImage',
content: `${publicPath}${iconPaths.msTileImage}${assetsVersionStr}`
content: getTagHref(publicPath, iconPaths.msTileImage, assetsVersionStr)
}),
makeTag('meta', {
name: 'msapplication-TileColor',
Expand Down Expand Up @@ -170,3 +170,11 @@ function makeTag (tagName, attributes, closeTag = false) {
attributes
}
}

function getTagHref (publicPath, href, assetsVersionStr) {
let tagHref = `${href}${assetsVersionStr}`
if (!(/(http(s?)):\/\//gi.test(href))) {
tagHref = `${publicPath}${tagHref}`
}
return tagHref
}

0 comments on commit 6c4a0bf

Please sign in to comment.