Skip to content

Commit 015d451

Browse files
committed
refactor: drop pwa
1 parent e469dd4 commit 015d451

File tree

6 files changed

+915
-2322
lines changed

6 files changed

+915
-2322
lines changed

package.json

+4-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"chart.js": "3.9.1",
1616
"idb": "^7.1.1",
1717
"less": "^4.1.2",
18-
"noty": "^3.2.0-beta-deprecated",
1918
"plausible-tracker": "^0.3.8",
2019
"react": "^18.2.0",
2120
"react-chartjs-2": "^4.3.1",
@@ -26,8 +25,8 @@
2625
"twemoji": "14.0.2"
2726
},
2827
"devDependencies": {
29-
"@types/react": "^18.0.25",
30-
"@types/react-dom": "^17.0.11",
28+
"@types/react": "^18.0.28",
29+
"@types/react-dom": "^18.0.11",
3130
"@types/react-helmet": "^6.1.5",
3231
"@types/twemoji": "^13.1.2",
3332
"@typescript-eslint/eslint-plugin": "^5.47.1",
@@ -42,9 +41,8 @@
4241
"prettier": "^2.8.1",
4342
"typescript": "^4.9.4",
4443
"vite": "^2.9.13",
45-
"vite-plugin-externals": "^0.5.0",
46-
"vite-plugin-html": "^3.2.0",
47-
"vite-plugin-pwa": "^0.12.0"
44+
"vite-plugin-externals": "0.5.0",
45+
"vite-plugin-html": "^3.2.0"
4846
},
4947
"lint-staged": {
5048
"*.{js,jsx,ts,tsx,css,less}": [

src/main.tsx

+18-36
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
import React, { lazy, useEffect, useState, Suspense } from 'react';
1+
import React, { lazy, Suspense, useEffect, useState } from 'react';
22
import { createRoot } from 'react-dom/client';
3-
import { registerSW } from 'virtual:pwa-register';
4-
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
53
import { Helmet } from 'react-helmet';
4+
import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom';
65
import { Container } from 'semantic-ui-react';
6+
7+
import {
8+
ErrorWhenLoadingOIerDb,
9+
NotSupportIndexedDB,
10+
} from '@/components/Errors';
11+
import Footer from '@/components/Footer';
12+
import Header from '@/components/Header';
13+
import Loading from '@/components/Loading';
714
import { initDb } from '@/libs/OIerDb';
815
import {
916
enableAutoPageviews,
1017
enableAutoTrackMultiDomain,
1118
} from '@/libs/plausible';
12-
import toast, { confirm } from '@/utils/toast';
13-
import Header from '@/components/Header';
14-
import Footer from '@/components/Footer';
15-
import {
16-
NotSupportIndexedDB,
17-
ErrorWhenLoadingOIerDb,
18-
} from '@/components/Errors';
19-
import Loading from '@/components/Loading';
2019

2120
// Pages
2221
const Home = lazy(() => import('@/pages/index'));
@@ -32,35 +31,18 @@ const About = lazy(() => import('@/pages/about'));
3231
// Styles
3332
import './main.css';
3433
import styles from './main.module.less';
35-
import 'noty/lib/noty.css';
36-
import 'noty/lib/themes/semanticui.css';
3734

3835
// 是否支持 indexedDB
3936
const notSupportIndexedDB = !globalThis || !globalThis.indexedDB;
4037

41-
const updateSW = registerSW({
42-
onNeedRefresh() {
43-
confirm.info('检测到新版本,是否更新?', [
44-
{
45-
name: '确定',
46-
color: 'green',
47-
callback() {
48-
localStorage.removeItem('staticSha512');
49-
localStorage.removeItem('resultSha512');
50-
51-
updateSW(true);
52-
},
53-
},
54-
{
55-
name: '取消',
56-
type: 'close',
57-
},
58-
]);
59-
},
60-
onOfflineReady() {
61-
toast.info('已完成脱机工作准备。', 3000);
62-
},
63-
});
38+
// 取消注册先前的 Service Worker
39+
if ('serviceWorker' in navigator) {
40+
navigator.serviceWorker.getRegistrations().then((registrations) => {
41+
for (let registration of registrations) {
42+
registration.unregister();
43+
}
44+
});
45+
}
6446

6547
const App: React.FC = () => {
6648
const [loadedOIerDb, setLoadedOIerDb] = useState(false);

src/utils/toast.ts

-69
This file was deleted.

tsconfig.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
"jsxFragmentFactory": "Fragment",
2020
"paths": {
2121
"@/*": ["./src/*"]
22-
},
23-
"types": [
24-
"vite-plugin-pwa/client"
25-
]
22+
}
2623
},
2724
"include": ["src"]
2825
}

vite.config.js

+4-123
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
/* eslint-disable */
22

3-
import { defineConfig, splitVendorChunkPlugin } from 'vite';
43
import react from '@vitejs/plugin-react';
5-
import { createHtmlPlugin } from 'vite-plugin-html';
6-
import { viteExternalsPlugin } from 'vite-plugin-externals';
7-
import { VitePWA } from 'vite-plugin-pwa';
8-
import path from 'path';
94
import crypto from 'crypto';
5+
import path from 'path';
6+
import { defineConfig, splitVendorChunkPlugin } from 'vite';
7+
import { viteExternalsPlugin } from 'vite-plugin-externals';
8+
import { createHtmlPlugin } from 'vite-plugin-html';
109

1110
const buildHash =
1211
/* Netlify */ process.env.COMMIT_REF ||
@@ -119,124 +118,6 @@ export default defineConfig(({ command }) => ({
119118
)
120119
),
121120
}),
122-
VitePWA({
123-
workbox: {
124-
sourcemap: true,
125-
maximumFileSizeToCacheInBytes: 1024 * 1024 * 1024, // 1024 MiB
126-
runtimeCaching: [
127-
{
128-
urlPattern: ({ url }) =>
129-
[
130-
'sb.cdn.baoshuo.ren',
131-
'oier.api.baoshuo.ren',
132-
'oierdb-ng.github.io',
133-
].includes(url.host),
134-
handler: 'NetworkFirst',
135-
options: {
136-
cacheName: 'oierdb-data-cache',
137-
expiration: {
138-
maxEntries: 100,
139-
maxAgeSeconds: 60 * 60 * 24 * 30, // <== 30 days
140-
},
141-
cacheableResponse: {
142-
statuses: [0, 200],
143-
},
144-
},
145-
},
146-
{
147-
urlPattern: /^https?:\/\/fonts\.googleapis\.com/i,
148-
handler: 'CacheFirst',
149-
options: {
150-
cacheName: 'google-fonts-cache',
151-
expiration: {
152-
maxEntries: 10,
153-
maxAgeSeconds: 60 * 60 * 24 * 365, // <== 365 days
154-
},
155-
cacheableResponse: {
156-
statuses: [0, 200],
157-
},
158-
},
159-
},
160-
{
161-
urlPattern: /^https?:\/\/fonts\.gstatic\.com/i,
162-
handler: 'CacheFirst',
163-
options: {
164-
cacheName: 'gstatic-fonts-cache',
165-
expiration: {
166-
maxEntries: 50,
167-
maxAgeSeconds: 60 * 60 * 24 * 365, // <== 365 days
168-
},
169-
cacheableResponse: {
170-
statuses: [0, 200],
171-
},
172-
},
173-
},
174-
{
175-
urlPattern: ({ url }) =>
176-
[
177-
'cdnjs.baoshuo.ren',
178-
'cdnjs.rsb.net',
179-
'cdnjs.loli.net',
180-
'cdnjs.cloudflare.com',
181-
].includes(url.host),
182-
handler: 'CacheFirst',
183-
options: {
184-
cacheName: 'cdnjs-cache',
185-
expiration: {
186-
maxEntries: 1000,
187-
maxAgeSeconds: 60 * 60 * 24 * 365, // <== 365 days
188-
},
189-
cacheableResponse: {
190-
statuses: [0, 200],
191-
},
192-
},
193-
},
194-
{
195-
urlPattern: /^https?:\/\/stat\.u\.sb\/.*\.js/i,
196-
handler: 'CacheFirst',
197-
options: {
198-
cacheName: 'analytics-cache',
199-
expiration: {
200-
maxEntries: 10,
201-
maxAgeSeconds: 60 * 60 * 24 * 7, // <== 7 days
202-
},
203-
cacheableResponse: {
204-
statuses: [0, 200],
205-
},
206-
},
207-
},
208-
{
209-
handler: 'NetworkOnly',
210-
urlPattern: /^https?:\/\/stat\.u\.sb\/api\/.*/i,
211-
method: 'POST',
212-
options: {
213-
backgroundSync: {
214-
name: 'analytics-queue',
215-
options: {
216-
maxRetentionTime: 24 * 60,
217-
},
218-
},
219-
},
220-
},
221-
],
222-
globPatterns: [
223-
'**/*.{js,css,png,jpg,jpeg,svg,gif,webp,ico,woff,woff2,ttf,eot,otf,html}',
224-
],
225-
},
226-
manifest: {
227-
name: 'OIerDb NG',
228-
short_name: 'OIerDb',
229-
description: 'Next Generation OIerDb.',
230-
theme_color: '#ffffff',
231-
icons: [
232-
{
233-
src: '/logo.png',
234-
sizes: '220x220',
235-
type: 'image/png',
236-
},
237-
],
238-
},
239-
}),
240121
],
241122
build: {
242123
sourcemap: true,

0 commit comments

Comments
 (0)