Skip to content

Commit 050fe2a

Browse files
qnpAkryum
authored andcommitted
feat(pwa): added options and updated readme (vuejs#1752)
* added options and updated readme * moved `manifest` out of `iconPaths` options * changed `iconsVersion` to `assetsVersion`
1 parent c6b06ec commit 050fe2a

File tree

2 files changed

+60
-9
lines changed

2 files changed

+60
-9
lines changed

packages/@vue/cli-plugin-pwa/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,34 @@ file, or the `"vue"` field in `package.json`.
5353

5454
- Default: `'default'`
5555

56+
- **pwa.assetsVersion**
57+
58+
- Default: `''`
59+
60+
This option is used if you need to add a version to your incons and manifest, against browser’s cache. This will append `?v=<pwa.assetsVersion>` to the URLs of the icons and manifest.
61+
62+
- **pwa.manifestPath**
63+
64+
- Default: `'manifest.json'`
65+
66+
The path of app’s manifest.
67+
68+
- **pwa.iconPaths**
69+
70+
- Defaults:
71+
72+
```js
73+
{
74+
favicon32: 'img/icons/favicon-32x32.png',
75+
favicon16: 'img/icons/favicon-16x16.png',
76+
appleTouchIcon: 'img/icons/apple-touch-icon-152x152.png',
77+
maskIcon: 'img/icons/safari-pinned-tab.svg',
78+
msTileImage: 'img/icons/msapplication-icon-144x144.png'
79+
}
80+
```
81+
82+
Change these values to use different paths for your icons.
83+
5684
### Example Configuration
5785

5886
```js

packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@ const defaults = {
55
themeColor: '#4DBA87', // The Vue color
66
msTileColor: '#000000',
77
appleMobileWebAppCapable: 'no',
8-
appleMobileWebAppStatusBarStyle: 'default'
8+
appleMobileWebAppStatusBarStyle: 'default',
9+
assetsVersion: '',
10+
manifestPath: 'manifest.json'
11+
}
12+
13+
const defaultIconPaths = {
14+
favicon32: 'img/icons/favicon-32x32.png',
15+
favicon16: 'img/icons/favicon-16x16.png',
16+
appleTouchIcon: 'img/icons/apple-touch-icon-152x152.png',
17+
maskIcon: 'img/icons/safari-pinned-tab.svg',
18+
msTileImage: 'img/icons/msapplication-icon-144x144.png'
919
}
1020

1121
module.exports = class HtmlPwaPlugin {
1222
constructor (options = {}) {
13-
this.options = Object.assign({}, defaults, options)
23+
const iconPaths = Object.assign({}, defaultIconPaths, options.iconPaths)
24+
delete options.iconPaths
25+
this.options = Object.assign({iconPaths: iconPaths}, defaults, options)
1426
}
1527

1628
apply (compiler) {
@@ -22,28 +34,39 @@ module.exports = class HtmlPwaPlugin {
2234
})
2335

2436
compilation.hooks.htmlWebpackPluginAlterAssetTags.tapAsync(ID, (data, cb) => {
25-
const { name, themeColor, msTileColor, appleMobileWebAppCapable, appleMobileWebAppStatusBarStyle } = this.options
37+
const {
38+
name,
39+
themeColor,
40+
msTileColor,
41+
appleMobileWebAppCapable,
42+
appleMobileWebAppStatusBarStyle,
43+
assetsVersion,
44+
manifestPath,
45+
iconPaths
46+
} = this.options
2647
const { publicPath } = compiler.options.output
2748

49+
const assetsVersionStr = assetsVersion ? `?v=${assetsVersion}` : ''
50+
2851
data.head.push(
2952
// Favicons
3053
makeTag('link', {
3154
rel: 'icon',
3255
type: 'image/png',
3356
sizes: '32x32',
34-
href: `${publicPath}img/icons/favicon-32x32.png`
57+
href: `${publicPath}${iconPaths.favicon32}${assetsVersionStr}`
3558
}),
3659
makeTag('link', {
3760
rel: 'icon',
3861
type: 'image/png',
3962
sizes: '16x16',
40-
href: `${publicPath}img/icons/favicon-16x16.png`
63+
href: `${publicPath}${iconPaths.favicon16}${assetsVersionStr}`
4164
}),
4265

4366
// Add to home screen for Android and modern mobile browsers
4467
makeTag('link', {
4568
rel: 'manifest',
46-
href: `${publicPath}manifest.json`
69+
href: `${publicPath}${manifestPath}${assetsVersionStr}`
4770
}),
4871
makeTag('meta', {
4972
name: 'theme-color',
@@ -65,18 +88,18 @@ module.exports = class HtmlPwaPlugin {
6588
}),
6689
makeTag('link', {
6790
rel: 'apple-touch-icon',
68-
href: `${publicPath}img/icons/apple-touch-icon-152x152.png`
91+
href: `${publicPath}${iconPaths.appleTouchIcon}${assetsVersionStr}`
6992
}),
7093
makeTag('link', {
7194
rel: 'mask-icon',
72-
href: `${publicPath}img/icons/safari-pinned-tab.svg`,
95+
href: `${publicPath}${iconPaths.maskIcon}${assetsVersionStr}`,
7396
color: themeColor
7497
}),
7598

7699
// Add to home screen for Windows
77100
makeTag('meta', {
78101
name: 'msapplication-TileImage',
79-
content: `${publicPath}img/icons/msapplication-icon-144x144.png`
102+
content: `${publicPath}${iconPaths.msTileImage}${assetsVersionStr}`
80103
}),
81104
makeTag('meta', {
82105
name: 'msapplication-TileColor',

0 commit comments

Comments
 (0)