Skip to content

Commit

Permalink
add service worker
Browse files Browse the repository at this point in the history
  • Loading branch information
BeiyanYunyi committed Jul 14, 2021
1 parent 20c4f21 commit ce9f849
Show file tree
Hide file tree
Showing 5 changed files with 1,379 additions and 22 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"redux-devtools-extension": "^2.13.9",
"redux-thunk": "^2.3.0",
"socket.io-client": "^4.1.3",
"vanta": "^0.5.21"
"vanta": "^0.5.21",
"vite-plugin-pwa": "^0.8.1"
},
"devDependencies": {
"@types/react": "^17.0.0",
Expand Down
7 changes: 7 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import React from "react";
import ReactDOM from "react-dom";
// eslint-disable-next-line import/no-unresolved
import { registerSW } from "virtual:pwa-register";
import App from "./App";

registerSW({
onOfflineReady() {
// show a ready to work offline to user
},
});
ReactDOM.render(<App />, document.getElementById("root"));
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
"jsx": "react",
"types": ["vite-plugin-pwa/client"]
},
"include": ["./src"]
}
10 changes: 10 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineConfig } from "vite";
import reactRefresh from "@vitejs/plugin-react-refresh";
import legacy from "@vitejs/plugin-legacy";
import { VitePWA } from "vite-plugin-pwa";

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -10,6 +11,15 @@ export default defineConfig({
targets: ["ie >= 11"],
additionalLegacyPolyfills: ["regenerator-runtime/runtime"],
}),
VitePWA({
registerType: "autoUpdate",
manifest: {
// content of manifest
},
workbox: {
// workbox options for generateSW
},
}),
],
server: { proxy: { "/api": { target: "http://127.0.0.1:3001/", ws: true } } },
});
Loading

0 comments on commit ce9f849

Please sign in to comment.