mirror of
https://github.com/outline/outline.git
synced 2026-11-22 22:02:35 +03:00
use vite-plugin-pwa instead of custom service worker code
This commit is contained in:
1 parent
f6de2b5c9f
commit
dddb050eb6
4 files changed
+1189
-526
No files matched your search
@@ -98,3 +98,34 @@ window.addEventListener("load", async () => {
|
||||
attributePrefix: "data-",
|
||||
});
|
||||
});
|
||||
|
||||
// To activate the Service Worker, execute the following code in the browser console and refresh:
|
||||
// localStorage.setItem("installServiceWorker", true)
|
||||
if ("serviceWorker" in navigator) {
|
||||
window.addEventListener("load", () => {
|
||||
if (!localStorage.getItem("installServiceWorker")) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("[ServiceWorker] Executing Service Worker code.");
|
||||
|
||||
// see: https://bugs.chromium.org/p/chromium/issues/detail?id=1097616
|
||||
// In some rare (<0.1% of cases) this call can return `undefined`
|
||||
const maybePromise = navigator.serviceWorker.register("/sw.js", {
|
||||
scope: "/",
|
||||
});
|
||||
|
||||
if (maybePromise?.then) {
|
||||
maybePromise
|
||||
.then((registration) => {
|
||||
console.log("[ServiceWorker] Registered.", registration);
|
||||
})
|
||||
.catch((registrationError) => {
|
||||
console.log(
|
||||
"[ServiceWorker] Registration failed. ",
|
||||
registrationError
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -223,6 +223,7 @@
|
||||
"uuid": "^8.3.2",
|
||||
"validator": "13.7.0",
|
||||
"vite": "^4.1.1",
|
||||
"vite-plugin-pwa": "^0.14.4",
|
||||
"winston": "^3.3.3",
|
||||
"workbox-precaching": "^6.5.4",
|
||||
"ws": "^7.5.3",
|
||||
|
||||
+59
-19
@@ -3,8 +3,9 @@ import react from "@vitejs/plugin-react";
|
||||
import browserslistToEsbuild from "browserslist-to-esbuild";
|
||||
import { webpackStats } from "rollup-plugin-webpack-stats";
|
||||
import { defineConfig } from "vite";
|
||||
import { VitePWA } from "vite-plugin-pwa";
|
||||
import { viteStaticCopy } from "vite-plugin-static-copy";
|
||||
import generateServiceWorker from "./vite/generateServiceWorker";
|
||||
// import generateServiceWorker from "./vite/generateServiceWorker";
|
||||
|
||||
export default () => {
|
||||
return defineConfig({
|
||||
@@ -24,9 +25,9 @@ export default () => {
|
||||
},
|
||||
},
|
||||
}),
|
||||
generateServiceWorker({
|
||||
cdnUrl: process.env.CDN_URL || "/",
|
||||
}),
|
||||
// generateServiceWorker({
|
||||
// cdnUrl: process.env.CDN_URL || "/",
|
||||
// }),
|
||||
viteStaticCopy({
|
||||
targets: [
|
||||
{
|
||||
@@ -35,6 +36,45 @@ export default () => {
|
||||
},
|
||||
],
|
||||
}),
|
||||
// https://vite-pwa-org.netlify.app/
|
||||
VitePWA({
|
||||
injectRegister: "inline",
|
||||
registerType: "autoUpdate",
|
||||
// includeAssets: ['favicon.ico', 'apple-touch-icon.png', 'masked-icon.svg'],
|
||||
manifest: {
|
||||
name: "Outline",
|
||||
short_name: "Outline",
|
||||
// description: "My Awesome App description",
|
||||
theme_color: "#fff",
|
||||
background_color: "#fff",
|
||||
start_url: "/",
|
||||
publicPath: "/static/",
|
||||
display: "standalone",
|
||||
// For Chrome, you must provide at least a 192x192 pixel icon, and a 512x512 pixel icon.
|
||||
// If only those two icon sizes are provided, Chrome will automatically scale the icons
|
||||
// to fit the device. If you'd prefer to scale your own icons, and adjust them for
|
||||
// pixel-perfection, provide icons in increments of 48dp.
|
||||
icons: [
|
||||
{
|
||||
src: "images/icon-512.png",
|
||||
sizes: "192x192",
|
||||
type: "image/png",
|
||||
},
|
||||
{
|
||||
src: "images/icon-512.png",
|
||||
sizes: "512x512",
|
||||
type: "image/png",
|
||||
},
|
||||
// last one duplicated for purpose: 'any maskable'
|
||||
{
|
||||
src: "images/icon-512.png",
|
||||
sizes: "512x512",
|
||||
type: "image/png",
|
||||
purpose: "any maskable",
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
],
|
||||
optimizeDeps: {
|
||||
esbuildOptions: {
|
||||
@@ -68,24 +108,24 @@ export default () => {
|
||||
*/
|
||||
input: {
|
||||
index: "./app/index.tsx",
|
||||
sw: "./app/sw/sw.ts",
|
||||
registerSW: "./app/sw/registerSW.ts",
|
||||
// sw: "./app/sw/sw.ts",
|
||||
// registerSW: "./app/sw/registerSW.ts",
|
||||
},
|
||||
output: [
|
||||
{
|
||||
entryFileNames: (chunkInfo) => {
|
||||
const isServiceWorker = ["sw", "registerSW"].includes(
|
||||
chunkInfo.name
|
||||
);
|
||||
// output: [
|
||||
// {
|
||||
// entryFileNames: (chunkInfo) => {
|
||||
// const isServiceWorker = ["sw", "registerSW"].includes(
|
||||
// chunkInfo.name
|
||||
// );
|
||||
|
||||
if (chunkInfo.isEntry && isServiceWorker) {
|
||||
return `sw/[name].js`;
|
||||
}
|
||||
// if (chunkInfo.isEntry && isServiceWorker) {
|
||||
// return `sw/[name].js`;
|
||||
// }
|
||||
|
||||
return `[name]-[hash].js`;
|
||||
},
|
||||
},
|
||||
],
|
||||
// return `[name]-[hash].js`;
|
||||
// },
|
||||
// },
|
||||
// ],
|
||||
plugins: [webpackStats()],
|
||||
},
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user