Merge pull request #46 from imsyy/dev

添加 PWA
This commit is contained in:
底层用户 2023-01-15 17:51:47 +08:00 committed by GitHub
commit 9ca1237f24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 5732 additions and 24 deletions

1
dev-dist/registerSW.js Normal file
View File

@ -0,0 +1 @@
if('serviceWorker' in navigator) navigator.serviceWorker.register('/dev-sw.js?dev-sw', { scope: '/', type: 'classic' })

92
dev-dist/sw.js Normal file
View File

@ -0,0 +1,92 @@
/**
* Copyright 2018 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// If the loader is already loaded, just stop.
if (!self.define) {
let registry = {};
// Used for `eval` and `importScripts` where we can't get script URL by other means.
// In both cases, it's safe to use a global var because those functions are synchronous.
let nextDefineUri;
const singleRequire = (uri, parentUri) => {
uri = new URL(uri + ".js", parentUri).href;
return registry[uri] || (
new Promise(resolve => {
if ("document" in self) {
const script = document.createElement("script");
script.src = uri;
script.onload = resolve;
document.head.appendChild(script);
} else {
nextDefineUri = uri;
importScripts(uri);
resolve();
}
})
.then(() => {
let promise = registry[uri];
if (!promise) {
throw new Error(`Module ${uri} didnt register its module`);
}
return promise;
})
);
};
self.define = (depsNames, factory) => {
const uri = nextDefineUri || ("document" in self ? document.currentScript.src : "") || location.href;
if (registry[uri]) {
// Module is already loading or loaded.
return;
}
let exports = {};
const require = depUri => singleRequire(depUri, uri);
const specialDeps = {
module: { uri },
exports,
require
};
registry[uri] = Promise.all(depsNames.map(
depName => specialDeps[depName] || require(depName)
)).then(deps => {
factory(...deps);
return exports;
});
};
}
define(['./workbox-148cb7e5'], (function (workbox) { 'use strict';
self.skipWaiting();
workbox.clientsClaim();
/**
* The precacheAndRoute() method efficiently caches and responds to
* requests for URLs in the manifest.
* See https://goo.gl/S9QRab
*/
workbox.precacheAndRoute([{
"url": "registerSW.js",
"revision": "3ca0b8505b4bec776b69afdba2768812"
}, {
"revision": null,
"url": "index.html"
}], {});
workbox.cleanupOutdatedCaches();
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
allowlist: [/^\/$/]
}));
}));

3394
dev-dist/workbox-148cb7e5.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -5,9 +5,10 @@
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta http-equiv="Access-Control-Allow-Origin" content="*"> <meta http-equiv="Access-Control-Allow-Origin" content="*">
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="一个默默无闻的主页"> <meta name="description" content="一个默默无闻的主页" />
<meta name="keywords" content="無名,个人主页"> <meta name="keywords" content="無名,个人主页" />
<meta name="author" content="無名"> <meta name="author" content="無名" />
<meta name="theme-color" content="#424242" />
<title><%- title %></title> <title><%- title %></title>
<!-- HarmonyOS Sans --> <!-- HarmonyOS Sans -->
<!-- 本站 CDN 已开启防盗链,非本站域名不可访问,请更改链接为下方内容,否则自定义字体将失效 --> <!-- 本站 CDN 已开启防盗链,非本站域名不可访问,请更改链接为下方内容,否则自定义字体将失效 -->

View File

@ -31,6 +31,7 @@
"unplugin-auto-import": "^0.11.2", "unplugin-auto-import": "^0.11.2",
"unplugin-vue-components": "^0.22.8", "unplugin-vue-components": "^0.22.8",
"vite": "^3.1.0", "vite": "^3.1.0",
"vite-plugin-html": "^3.2.0" "vite-plugin-html": "^3.2.0",
"vite-plugin-pwa": "^0.14.1"
} }
} }

View File

@ -15,3 +15,13 @@ pinia.use(piniaPluginPersistedstate);
app.use(pinia); app.use(pinia);
app.mount('#app') app.mount('#app')
// if ('serviceWorker' in navigator) {
// navigator.serviceWorker.register('/sw.js')
// .then(() => {
// console.log('Service worker registered.');
// })
// .catch(err => {
// console.log('Failed to register service worker: ', err);
// });
// }

View File

@ -14,6 +14,9 @@ import {
import { import {
resolve resolve
} from 'path'; } from 'path';
import {
VitePWA
} from 'vite-plugin-pwa';
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default ({ export default ({
@ -36,6 +39,67 @@ export default ({
}, },
}, },
}), }),
VitePWA({
registerType: 'autoUpdate',
devOptions: {
enabled: true
},
workbox: {
runtimeCaching: [{
urlPattern: /(.*?)\.(js|css|woff2|woff|ttf)/, // js / css 静态资源缓存
handler: 'CacheFirst',
options: {
cacheName: 'js-css-cache',
},
},
{
urlPattern: /(.*?)\.(png|jpe?g|svg|gif|bmp|psd|tiff|tga|eps)/, // 图片缓存
handler: 'CacheFirst',
options: {
cacheName: 'image-cache',
},
},
],
},
manifest: {
"name": "無名の主页",
"short_name": "無名の主页",
"description": "一个默默无闻的主页",
"display": "standalone",
"start_url": "/",
"theme_color": "#424242",
"background_color": "#424242",
"icons": [{
"src": "/images/icon/48.png",
"sizes": "48x48",
"type": "image/png"
}, {
"src": "/images/icon/72.png",
"sizes": "72x72",
"type": "image/png"
}, {
"src": "/images/icon/96.png",
"sizes": "96x96",
"type": "image/png"
}, {
"src": "/images/icon/128.png",
"sizes": "128x128",
"type": "image/png"
}, {
"src": "/images/icon/144.png",
"sizes": "144x144",
"type": "image/png"
}, {
"src": "/images/icon/192.png",
"sizes": "192x192",
"type": "image/png"
}, {
"src": "/images/icon/512.png",
"sizes": "512x512",
"type": "image/png"
}]
}
}),
], ],
server: { server: {
port: "3000", port: "3000",

2181
yarn.lock

File diff suppressed because it is too large Load Diff