Replies: 2 comments 2 replies
-
Oh, I see now that there's @bluwy's |
Beta Was this translation helpful? Give feedback.
2 replies
-
I guess this is best done as a Vite plugin than being baked in. Here's a simple Vite 3 plugin (for // vite.config.ts
import { defineConfig, type Plugin, type ViteDevServer } from 'vite'
import vue from '@vitejs/plugin-vue'
import qrcode from 'qrcode'
const qrcodeServerUrl = (): Plugin => {
let origPrintUrls = () => { }
const logUrlAsQrCode = (url: string) => {
qrcode.toString(url, { type: 'terminal', small: true }, (err, urlQrCode) => {
if (err) {
console.warn('cannot generate qrcode', err)
} else {
console.log() // empty line for margin
console.log(urlQrCode)
}
})
}
return {
apply: 'serve',
name: 'qrcode-server-url',
configureServer(server: ViteDevServer) {
origPrintUrls = server.printUrls
server.printUrls = () => {
origPrintUrls()
server.resolvedUrls.network?.forEach(url => logUrlAsQrCode(url))
}
}
}
}
export default defineConfig({
plugins: [vue(), qrcodeServerUrl()]
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In addition to logging the network URL in the console, it would be handy to also log the QR Code to enable quickly opening the Vite app in mobile browsers (e.g., using
qrcode
).Example:

Beta Was this translation helpful? Give feedback.
All reactions