-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
54 lines (49 loc) · 1.56 KB
/
index.tsx
File metadata and controls
54 lines (49 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import ReactDOM from 'react-dom/client'
import ReactGA from 'react-ga4'
import { Provider } from 'react-redux'
import { BrowserRouter } from 'react-router-dom'
import './index.css'
import 'swiper/css'
import 'swiper/css/navigation'
import 'swiper/css/pagination'
import App from './App'
import { GlobalConfigProvider } from './GlobalContext'
import 'react-lazy-load-image-component/src/effects/blur.css'
import './i18n'
import store from './store'
if (import.meta.env.NODE_ENV === 'production') {
ReactGA.initialize('G-69VXS5Z1FV')
}
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement)
root.render(
<BrowserRouter>
<Provider store={store}>
<GlobalConfigProvider>
<App />
</GlobalConfigProvider>
</Provider>
</BrowserRouter>
)
if ('serviceWorker' in navigator) {
if (import.meta.env.NODE_ENV === 'production') {
// ✅ 正式環境才註冊 Service Worker
window.addEventListener('load', () => {
navigator.serviceWorker
.register('/service-worker.js')
.then(reg => {
console.log('✅ Service Worker registered:', reg)
})
.catch(err => console.error('❌ Service Worker registration failed:', err))
})
} else {
// 🧹 開發環境清除快取與已註冊 Service Worker
// navigator.serviceWorker.getRegistrations().then((registrations) => {
// for (let registration of registrations) {
// registration.unregister();
// }
// });
// caches.keys().then((names) => {
// for (let name of names) caches.delete(name);
// });
}
}