From 07633bce074590dcd67d7ee95791d6bc5ca4a34d Mon Sep 17 00:00:00 2001 From: Gabriel Martins Date: Tue, 25 Aug 2020 04:58:28 -0300 Subject: [PATCH 1/4] fix: Fix always insert theme color tags --- .../@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js b/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js index 25b4bfbe2a..13d983ffd0 100644 --- a/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js +++ b/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js @@ -51,13 +51,13 @@ const defaultIconPaths = { } module.exports = class HtmlPwaPlugin { - constructor (options = {}) { + constructor(options = {}) { const iconPaths = Object.assign({}, defaultIconPaths, options.iconPaths) delete options.iconPaths this.options = Object.assign({ iconPaths: iconPaths }, defaults, options) } - apply (compiler) { + apply(compiler) { compiler.hooks.compilation.tap(ID, compilation => { compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing.tapAsync(ID, (data, cb) => { // wrap favicon in the base template with IE only comment @@ -111,13 +111,18 @@ module.exports = class HtmlPwaPlugin { rel: 'manifest', href: getTagHref(publicPath, manifestPath, assetsVersionStr) } - ), - makeTag('meta', { - name: 'theme-color', - content: themeColor - }) + ) ) + if (themeColor !== null) { + data.head.push( + makeTag('meta', { + name: 'theme-color', + content: themeColor + }) + ) + } + // Add to home screen for Safari on iOS data.head.push( makeTag('meta', { @@ -154,12 +159,14 @@ module.exports = class HtmlPwaPlugin { content: getTagHref(publicPath, iconPaths.msTileImage, assetsVersionStr) })) } - data.head.push( - makeTag('meta', { - name: 'msapplication-TileColor', - content: msTileColor - }) - ) + if (msTileColor !== null) { + data.head.push( + makeTag('meta', { + name: 'msapplication-TileColor', + content: msTileColor + }) + ) + } cb(null, data) }) @@ -191,7 +198,7 @@ module.exports = class HtmlPwaPlugin { } } -function makeTag (tagName, attributes, closeTag = false) { +function makeTag(tagName, attributes, closeTag = false) { return { tagName, closeTag, @@ -199,7 +206,7 @@ function makeTag (tagName, attributes, closeTag = false) { } } -function getTagHref (publicPath, href, assetsVersionStr) { +function getTagHref(publicPath, href, assetsVersionStr) { let tagHref = `${href}${assetsVersionStr}` if (!isHrefAbsoluteUrl(href)) { tagHref = `${publicPath}${tagHref}` @@ -207,6 +214,6 @@ function getTagHref (publicPath, href, assetsVersionStr) { return tagHref } -function isHrefAbsoluteUrl (href) { +function isHrefAbsoluteUrl(href) { return /(http(s?)):\/\//gi.test(href) } From c25a6ec266f1af6e518506de84c421eb0bbad911 Mon Sep 17 00:00:00 2001 From: Gabriel Martins Date: Tue, 25 Aug 2020 15:40:50 -0300 Subject: [PATCH 2/4] style: fix code format --- packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js b/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js index 13d983ffd0..8e44063c53 100644 --- a/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js +++ b/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js @@ -51,13 +51,13 @@ const defaultIconPaths = { } module.exports = class HtmlPwaPlugin { - constructor(options = {}) { + constructor (options = {}) { const iconPaths = Object.assign({}, defaultIconPaths, options.iconPaths) delete options.iconPaths this.options = Object.assign({ iconPaths: iconPaths }, defaults, options) } - apply(compiler) { + apply (compiler) { compiler.hooks.compilation.tap(ID, compilation => { compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing.tapAsync(ID, (data, cb) => { // wrap favicon in the base template with IE only comment @@ -198,7 +198,7 @@ module.exports = class HtmlPwaPlugin { } } -function makeTag(tagName, attributes, closeTag = false) { +function makeTag (tagName, attributes, closeTag = false) { return { tagName, closeTag, @@ -206,7 +206,7 @@ function makeTag(tagName, attributes, closeTag = false) { } } -function getTagHref(publicPath, href, assetsVersionStr) { +function getTagHref (publicPath, href, assetsVersionStr) { let tagHref = `${href}${assetsVersionStr}` if (!isHrefAbsoluteUrl(href)) { tagHref = `${publicPath}${tagHref}` @@ -214,6 +214,6 @@ function getTagHref(publicPath, href, assetsVersionStr) { return tagHref } -function isHrefAbsoluteUrl(href) { +function isHrefAbsoluteUrl (href) { return /(http(s?)):\/\//gi.test(href) } From 13e4275a8ec689177d7a183d878865266210211e Mon Sep 17 00:00:00 2001 From: GabrielGMartinsBr Date: Fri, 28 Aug 2020 15:10:30 -0300 Subject: [PATCH 3/4] Update packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js Co-authored-by: Haoqun Jiang --- packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js b/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js index 8e44063c53..4914cc1625 100644 --- a/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js +++ b/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js @@ -114,7 +114,7 @@ module.exports = class HtmlPwaPlugin { ) ) - if (themeColor !== null) { + if (themeColor != null) { data.head.push( makeTag('meta', { name: 'theme-color', From 722e0b0afcb0941320027eb5446a74be838489a3 Mon Sep 17 00:00:00 2001 From: GabrielGMartinsBr Date: Fri, 28 Aug 2020 15:10:45 -0300 Subject: [PATCH 4/4] Update packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js Co-authored-by: Haoqun Jiang --- packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js b/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js index 4914cc1625..f6683ef47e 100644 --- a/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js +++ b/packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js @@ -159,7 +159,7 @@ module.exports = class HtmlPwaPlugin { content: getTagHref(publicPath, iconPaths.msTileImage, assetsVersionStr) })) } - if (msTileColor !== null) { + if (msTileColor != null) { data.head.push( makeTag('meta', { name: 'msapplication-TileColor',