Enable QR in vite preview mode
Closed this issue ยท 6 comments
Describe the problem
Currently the QR code only displays when vite is running in dev mode, ie. vite serve
. When testing a PWA, we are also building the site locally using vite build
, then previewing it using vite preview
.
I'd like to be able to view the QR code when vite is running in preview mode via vite preview
as well.
Describe the proposed solution
An additional preview
option, which can default to false
, to preserve existing behavior but allow developers to opt-in to showing the QR code during vite preview
.
Alternatives considered
No alternatives at this stage - potentially forking the project.
Importance
would make my life easier
This could be pretty easy to implement using the configurePreviewServer
hook https://vitejs.dev/guide/api-plugin.html#configurepreviewserver similar to how we already use configureServer
here https://github.com/svitejs/vite-plugin-qrcode/blob/main/packages/vite-plugin-qrcode/src/index.ts#L8
Would you like to contribute this? PR welcome.
Certainly ๐ will raise a PR when I get a chance!
Hmm looks like you're right. We could get logger
with the configResolved
hook, but resolvedUrls
is tricky unless we re-implement it ourselves. Another way is to send a PR to Vite to provide the PreviewServer
type in the configurePreviewServer
hook instead.
Hmm looks like you're right. We could get
logger
with theconfigResolved
hook, butresolvedUrls
is tricky unless we re-implement it ourselves. Another way is to send a PR to Vite to provide thePreviewServer
type in theconfigurePreviewServer
hook instead.
i think updating the configurePreviewServer hook in vite is a good idea. Even better that vite-4 is currently in alpha so doing it now has a nice chance of getting included. esp if it aligns the hook api's to be more similar.
I'll try get a PR up for Vite soon. Good call on Vite 4 being alpha, I've been keeping an eye on that for the Rollup upgrade too.