Skip to content

Commit a81ef8a

Browse files
authored
doc: Add an example of a fully PWA-compliant config for pwa-plugin (#1769)
1 parent 6d47c9e commit a81ef8a

File tree

2 files changed

+66
-7
lines changed

2 files changed

+66
-7
lines changed

packages/docs/docs/plugin/official/plugin-pwa.md

+33-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,37 @@ module.exports = {
2222
}
2323
```
2424

25+
::: tip
26+
To make your site fully PWA-compliant, you need to:
27+
28+
- provide a web app manifest and icons in `.vuepress/public`,
29+
- add correct [head links](/config/#head) in `.vuepress/config.js` (see example below).
30+
31+
For more details, see [MDN docs about the Web App Manifest](https://developer.mozilla.org/en-US/docs/Web/Manifest).
32+
:::
33+
34+
Here is an example of a fully PWA-compliant configuration with VuePress:
35+
36+
```javascript
37+
module.exports = {
38+
head: [
39+
['link', { rel: 'icon', href: '/logo.png' }],
40+
['link', { rel: 'manifest', href: '/manifest.json' }],
41+
['meta', { name: 'theme-color', content: '#3eaf7c' }],
42+
['meta', { name: 'apple-mobile-web-app-capable', content: 'yes' }],
43+
['meta', { name: 'apple-mobile-web-app-status-bar-style', content: 'black' }],
44+
['link', { rel: 'apple-touch-icon', href: '/icons/apple-touch-icon-152x152.png' }],
45+
['link', { rel: 'mask-icon', href: '/icons/safari-pinned-tab.svg', color: '#3eaf7c' }],
46+
['meta', { name: 'msapplication-TileImage', content: '/icons/msapplication-icon-144x144.png' }],
47+
['meta', { name: 'msapplication-TileColor', content: '#000000' }]
48+
],
49+
['@vuepress/pwa', {
50+
serviceWorker: true,
51+
updatePopup: true
52+
}],
53+
}
54+
```
55+
2556
## Options
2657

2758
### serviceWorker
@@ -39,10 +70,8 @@ There is a aliased module `@sw-event` module that will also be emitting the foll
3970
- `sw-offline`
4071
- `sw-error`
4172

42-
::: tip PWA NOTES
43-
The `serviceWorker` option only handles the service worker. To make your site fully PWA-compliant, you will need to provide the Web App Manifest and icons in `.vuepress/public`. For more details, see [MDN docs about the Web App Manifest](https://developer.mozilla.org/en-US/docs/Web/Manifest).
44-
45-
Also, only enable this if you are able to deploy your site with SSL, since service worker can only be registered under HTTPs URLs.
73+
::: tip
74+
Since you can only register service workers under HTTPs URLs, make sure you can deploy your site with SSL before enabling this option.
4675
:::
4776

4877
### generateSWConfig

packages/docs/docs/zh/plugin/official/plugin-pwa.md

+33-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,37 @@ module.exports = {
2222
}
2323
```
2424

25+
::: tip
26+
为了让你的网站完全地兼容 PWA,你需要:
27+
28+
-`.vuepress/public` 提供 Manifest 和 icons
29+
-`.vuepress/config.js` 添加正確的 [head links](/config/#head)(参见下面例子).
30+
31+
更多细节,请参见 [MDN docs about the Web App Manifest](https://developer.mozilla.org/en-US/docs/Web/Manifest).
32+
:::
33+
34+
这是一个在VuePress中完全地兼容 PWA 的例子:
35+
36+
```javascript
37+
module.exports = {
38+
head: [
39+
['link', { rel: 'icon', href: '/logo.png' }],
40+
['link', { rel: 'manifest', href: '/manifest.json' }],
41+
['meta', { name: 'theme-color', content: '#3eaf7c' }],
42+
['meta', { name: 'apple-mobile-web-app-capable', content: 'yes' }],
43+
['meta', { name: 'apple-mobile-web-app-status-bar-style', content: 'black' }],
44+
['link', { rel: 'apple-touch-icon', href: '/icons/apple-touch-icon-152x152.png' }],
45+
['link', { rel: 'mask-icon', href: '/icons/safari-pinned-tab.svg', color: '#3eaf7c' }],
46+
['meta', { name: 'msapplication-TileImage', content: '/icons/msapplication-icon-144x144.png' }],
47+
['meta', { name: 'msapplication-TileColor', content: '#000000' }]
48+
],
49+
['@vuepress/pwa', {
50+
serviceWorker: true,
51+
updatePopup: true
52+
}],
53+
}
54+
```
55+
2556
## 选项
2657

2758
### serviceWorker
@@ -39,9 +70,8 @@ module.exports = {
3970
- `sw-offline`
4071
- `sw-error`
4172

42-
::: tip PWA NOTES
43-
`serviceWorker` 选项仅仅用来控制 service worker,为了让你的网站完全地兼容 PWA,你需要在 `.vuepress/public` 提供 Manifest 和 icons,更多细节,请参见 [MDN docs about the Web App Manifest](https://developer.mozilla.org/en-US/docs/Web/Manifest).
44-
此外,只有您能够使用 SSL 部署您的站点时才能启用此功能,因为 service worker 只能在 HTTPs 的 URL 下注册。
73+
::: tip
74+
只有在你能够使用 SSL 部署您的站点时才能启用此功能,因为 service worker 只能在 HTTPs 的 URL 下注册。
4575
:::
4676

4777
### generateSWConfig

0 commit comments

Comments
 (0)