sw works in production build
This commit is contained in:
@ -49,7 +49,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"start": "vite",
|
||||
"build": "vite build",
|
||||
"build": "yarn eslint --fix && vite build",
|
||||
"serve": "vite preview",
|
||||
"test": "jest --runInBand",
|
||||
"intl-extract": "formatjs extract 'src/**/*.ts*' --ignore='**/*.d.ts' --out-file src/lang.json --flatten true",
|
||||
@ -126,6 +126,7 @@
|
||||
"ts-loader": "^9.4.4",
|
||||
"typescript": "^5.2.2",
|
||||
"vite": "^5.0.0",
|
||||
"vite-plugin-pwa": "^0.17.0",
|
||||
"webpack": "^5.88.2",
|
||||
"webpack-bundle-analyzer": "^4.8.0",
|
||||
"webpack-cli": "^5.1.4",
|
||||
|
@ -1,14 +1,15 @@
|
||||
// Import the service worker with Vite's special syntax
|
||||
import ServiceWorkerURL from "./service-worker?worker&url";
|
||||
//import ServiceWorkerURL from "./service-worker?worker&url";
|
||||
|
||||
export function register() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', () => {
|
||||
registerValidSW(ServiceWorkerURL);
|
||||
//registerValidSW(ServiceWorkerURL);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
async function registerValidSW(swUrl: string) {
|
||||
try {
|
||||
const registration = await navigator.serviceWorker.register(swUrl,
|
||||
@ -33,6 +34,8 @@ async function registerValidSW(swUrl: string) {
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
export async function unregister() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
const registration = await navigator.serviceWorker.ready;
|
||||
|
@ -1,10 +1,22 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import { VitePWA } from 'vite-plugin-pwa';
|
||||
|
||||
import appConfig from "config";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
plugins: [
|
||||
react(),
|
||||
VitePWA({
|
||||
strategies: 'injectManifest',
|
||||
srcDir: 'src',
|
||||
filename: 'service-worker.ts',
|
||||
devOptions: {
|
||||
enabled: true,
|
||||
type: 'module',
|
||||
}
|
||||
})
|
||||
],
|
||||
assetsInclude: ['**/*.md'],
|
||||
resolve: {
|
||||
alias: {
|
||||
|
Reference in New Issue
Block a user