final notif changes
This commit is contained in:
@@ -20,29 +20,28 @@ function swPlugin() {
|
||||
config(_: unknown, { mode }: { mode: string }) {
|
||||
env = loadEnv(mode, process.cwd(), '')
|
||||
},
|
||||
// Dev server: serve firebase-messaging-sw.js with injected config
|
||||
// Dev server: serve sw.js with injected Firebase config
|
||||
configureServer(server: { middlewares: { use: (path: string, handler: (req: unknown, res: { setHeader: (k: string, v: string) => void; end: (s: string) => void }, next: () => void) => void) => void } }) {
|
||||
server.middlewares.use('/firebase-messaging-sw.js', (_req, res) => {
|
||||
const swPath = path.resolve(__dirname, 'public/firebase-messaging-sw.js')
|
||||
server.middlewares.use('/sw.js', (_req, res) => {
|
||||
const swPath = path.resolve(__dirname, 'public/sw.js')
|
||||
if (fs.existsSync(swPath)) {
|
||||
const content = injectFirebaseConfig(fs.readFileSync(swPath, 'utf-8'), env)
|
||||
const content = injectFirebaseConfig(
|
||||
fs.readFileSync(swPath, 'utf-8').replace('__BUILD_TIME__', 'dev'),
|
||||
env
|
||||
)
|
||||
res.setHeader('Content-Type', 'application/javascript')
|
||||
res.end(content)
|
||||
}
|
||||
})
|
||||
},
|
||||
closeBundle() {
|
||||
// Cache-bust the main service worker
|
||||
// Cache-bust sw.js and inject Firebase config
|
||||
const swPath = path.resolve(__dirname, 'dist/sw.js')
|
||||
if (fs.existsSync(swPath)) {
|
||||
const content = fs.readFileSync(swPath, 'utf-8')
|
||||
fs.writeFileSync(swPath, content.replace('__BUILD_TIME__', Date.now().toString()))
|
||||
}
|
||||
// Inject Firebase config into the FCM service worker
|
||||
const fswPath = path.resolve(__dirname, 'dist/firebase-messaging-sw.js')
|
||||
if (fs.existsSync(fswPath)) {
|
||||
const content = injectFirebaseConfig(fs.readFileSync(fswPath, 'utf-8'), env)
|
||||
fs.writeFileSync(fswPath, content)
|
||||
let content = fs.readFileSync(swPath, 'utf-8')
|
||||
content = content.replace('__BUILD_TIME__', Date.now().toString())
|
||||
content = injectFirebaseConfig(content, env)
|
||||
fs.writeFileSync(swPath, content)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user