Closed userquin closed 1 year ago
@brc-dd the problem is the following:
The VitePress head configuration is static (IIRC), the PWA may need to inject the webmanifest link and the registerSW.js
or the same code but inlined (register the service worker in the browser).
In dev, there is no need to inject anything (pwa dev options will be disabled or throw error: I will check if we can use it to test the webmanifest).
So, we need to check if we're running dev server or building the app, but we also need to do a few more things, since the pwa plugin will do a lot of automatic work, depending on the user configuration and the usage: for example, the pwa plugin exposes a set of virtual modules to integrate with the client allowing interacting, such as prompt
dialog before updating the app once detected a new version.
If the user is importing any of the virtual modules exposed by the pwa plugin, then, there is no need to inject the registerSW.js
or its inlined version, but will require to inject the header link.
If you run the dev server in the example, there will be a few errors, since the webmanifest and registerSW.js
will not be generated.
I need to test it importing virtual from pwa on the pwa-prompt example!
We need:
injectRegister
to be'virtual' | 'script' | 'inline'
: defaults toscript
?registerSW.js
orinline
code to register the sw wheninjectRegister !== 'virtual'
(if using virtual, just ignore it)