-
I'm trying to implement Firebase messaging. It requires a file: firebase-messaging-sw.js in root directory. I'm testing my website on GitHub pages in directory, so I set this: baseUrl: process.env.NODE_ENV === 'production' ? '/jquery.terminal-docs/' : '', And put the file in /static directory. The worker is registered, but I think that It needs to be bundled, since the documentation only say to write this code: import { getMessaging, onMessage } from 'firebase/messaging';
const messaging = getMessaging();
onMessage(messaging, (payload) => {
console.log('Message received. ', payload);
// ...
}); How can I compile this static file so the Do you have any example of using service worker written in TypeScript? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I don't really understand the problem sorry. Files in You can use the clientModule config/plugin API to include additional client-side code bundled alongside all the rest of the Docusaurus client app. Our PWA plugin uses a service worker: https://github.com/facebook/docusaurus/tree/main/packages/docusaurus-plugin-pwa |
Beta Was this translation helpful? Give feedback.
Yes it's comppiled in a postBuild plugin lifecycle hook. Note you don't necessarily have to do this. In our case we do this because we use modern syntax in it, but you can also write syntax that works directly in browsers without having to downgrade syntax.
Compilation is not mandatory, and if you do compile, you can do it with the tools of your choice (not even necessarily webpack/Rspack like us)
But here's our pwa plugin code reusing our compilation infrastructure