pnsk-lab / vite-sw

A plugin for writing Service Worker on Vite
https://www.npmjs.com/vite-sw
6 stars 0 forks source link

compare to manual approach #1

Open 7flash opened 2 weeks ago

7flash commented 2 weeks ago

Currently I am registering service worker in my vite app manually,

and I wonder if I can integrate this package, and how I can do it

https://github.com/galaxydo/june-tenth-app/blob/master/src/may16-galaxy-frontend/vite.config.js#L27

nakasyou commented 2 weeks ago

Probably you'll get success if you do that:

  1. Install vite-sw
  2. Register vite-sw as Vite plugin
  3. Import in https://github.com/galaxydo/june-tenth-app/blob/7ba4e92713688f51a7cd7688e66c2c25fc82f87c/src/may16-galaxy-frontend/index.ts:
    import registerSW from './src/sw/index.tsx?sw'
  4. Replace https://github.com/galaxydo/june-tenth-app/blob/7ba4e92713688f51a7cd7688e66c2c25fc82f87c/src/may16-galaxy-frontend/index.ts#L47 with
    registerSW({
    scope: '/',
    type: 'module'
    })
7flash commented 2 weeks ago

but i need to pass some env variables as url params when registering, possible with vite-sw?

nakasyou commented 2 weeks ago

@7flash, no it's not possible. I'll think for that.