Skip to content

Commit fd7ffbc

Browse files
committed
[add] PWA configuration
1 parent 853d19e commit fd7ffbc

File tree

5 files changed

+60
-11
lines changed

5 files changed

+60
-11
lines changed

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"version": "1.0.0-beta",
44
"description": "Re-implemented Official Document site of BootStrap & FontAwesome based on WebCell, BootCell & MarkCell",
55
"dependencies": {
6-
"@nuintun/qrcode": "^3.0.0",
6+
"@nuintun/qrcode": "^3.0.1",
77
"@tech_query/snabbdom-looks-like": "^2.0.0",
8-
"boot-cell": "^1.0.0-rc.37",
8+
"boot-cell": "^1.0.0-rc.38",
99
"bootstrap-icons": "^1.0.0-alpha5",
1010
"cell-router": "^2.0.0-rc.8",
1111
"classnames": "^2.2.6",
@@ -33,7 +33,8 @@
3333
"parcel": "^1.12.4",
3434
"postcss-modules": "^3.2.0",
3535
"prettier": "^2.0.5",
36-
"typescript": "^3.9.7"
36+
"typescript": "^3.9.7",
37+
"workbox-cli": "^4.3.1"
3738
},
3839
"prettier": {
3940
"singleQuote": true,
@@ -52,9 +53,9 @@
5253
"scripts": {
5354
"test": "lint-staged",
5455
"pack-mdx": "rm -rf document/dist/ && mark-cell document/source -p web-cell -f createCell",
55-
"pack-tsx": "rm -rf dist/ && parcel build source/index.html --public-url .",
56-
"build": "npm run pack-mdx && npm run pack-tsx",
57-
"start": "npm run pack-mdx && rm -rf dist/ && parcel source/index.html --open"
56+
"pack-tsx": "parcel build source/index.html --public-url .",
57+
"build": "npm run pack-mdx && rm -rf dist/ && npm run pack-tsx && workbox generateSW",
58+
"start": "npm run pack-mdx && workbox generateSW && parcel source/index.html --open"
5859
},
5960
"husky": {
6061
"hooks": {

source/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/>
1010
<title>BootCell</title>
1111
<link rel="icon" href="https://web-cell.dev/WebCell-0.f1ffd28b.png" />
12+
<link rel="manifest" href="index.webmanifest" />
13+
<script src="https://cdn.jsdelivr.net/npm/pwacompat@2.0.15/pwacompat.min.js"></script>
1214
<link
1315
rel="stylesheet"
1416
href="https://cdn.jsdelivr.net/npm/dialog-polyfill@0.5.2/dist/dialog-polyfill.css"

source/index.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1-
import { documentReady, render, createCell } from 'web-cell';
2-
3-
import { PageRouter } from './page';
4-
5-
documentReady.then(() => render(<PageRouter />));
1+
import { serviceWorkerUpdate } from 'web-utility';
2+
import { documentReady, render, createCell } from 'web-cell';
3+
4+
import { PageRouter } from './page';
5+
6+
const { serviceWorker } = window.navigator;
7+
8+
serviceWorker
9+
?.register('sw.js')
10+
.then(serviceWorkerUpdate)
11+
.then(worker => {
12+
if (window.confirm('New version of this Web App detected, update now?'))
13+
worker.postMessage({ type: 'SKIP_WAITING' });
14+
});
15+
16+
serviceWorker?.addEventListener('controllerchange', () =>
17+
window.location.reload()
18+
);
19+
20+
documentReady.then(() => render(<PageRouter />));

source/index.webmanifest

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "BootCell",
3+
"short_name": "BootCell",
4+
"start_url": "https://bootstrap.web-cell.dev/",
5+
"description": "Web Components UI library based on WebCell v2, BootStrap v4, BootStrap Icon v1 & FontAwesome v5",
6+
"scope": "/",
7+
"display": "standalone",
8+
"orientation": "any",
9+
"lang": "zh-CN",
10+
"dir": "ltr",
11+
"theme_color": "rgba(0,0,0,0.5)",
12+
"background_color": "transparent",
13+
"icons": [
14+
{
15+
"src": "https://web-cell.dev/WebCell-0.f1ffd28b.png",
16+
"type": "image/png",
17+
"sizes": "300x300"
18+
}
19+
]
20+
}

workbox-config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
globDirectory: 'dist/',
3+
globPatterns: ['**/*.{html,css,js,json,ico,gif,jpg,jpeg,png,webp}'],
4+
swDest: 'dist/sw.js',
5+
importWorkboxFrom: 'disabled',
6+
importScripts: [
7+
'https://cdn.jsdelivr.net/npm/workbox-sw@4.3.1/build/workbox-sw.min.js'
8+
],
9+
clientsClaim: true,
10+
cleanupOutdatedCaches: true
11+
};

0 commit comments

Comments
 (0)