vite-live-preview is a Vite plugin designed to provide a live preview server specifically for Vite builds executed with the `--watch` flag. Unlike the standard `vite dev` server, which prioritizes Hot Module Replacement (HMR) for rapid development, this plugin focuses on serving a production-like build output, automatically reloading the browser page whenever a rebuild completes. The current stable version is 0.4.0, and the project appears actively maintained on GitHub, with recent updates. A key differentiator is its explicit non-support for HMR, making it suitable for scenarios where a full page reload is acceptable or preferred, or when simulating a built artifact in a watch mode. It allows for detailed configuration of the preview server, including port settings, reload delays, and handling of complex network setups like reverse proxies via a `clientPort` option. Developers should note that Vite plugins configured in the main `vite.config.ts` are not automatically inherited by the preview server and must be re-added via the plugin's `config` option if needed.
npm install vite-live-previewVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic setup of the `vite-live-preview` plugin, enabling a preview server for watched Vite builds with automatic browser reloading and custom port configuration, including debug options and an example of plugin re-addition for the preview server.
If HMR is required, use the standard `vite dev` command instead of `vite build --watch` with `vite-live-preview`.
Pass an object to the `config` option within the `preview()` plugin, and include the necessary plugins in its `plugins` array: `preview({ config: { plugins: [yourPlugin()] } })`.Always use `npx vite build --watch` to ensure the preview server is launched alongside the watching build process.
If the client cannot connect to the WebSocket for reloads, configure the `reload.clientPort` option to the port the client should use for the WebSocket connection, bypassing the reverse proxy's remapping if necessary. `preview({ reload: { clientPort: 80 } })`For HMR, use Vite's standard development server (`npx vite dev`). `vite-live-preview` is for watchable builds with full page reloads.
You must explicitly re-add any required plugins for the preview server within the `config` option of the `preview()` plugin, e.g., `preview({ config: { plugins: [vue()] } })`.Ensure you are using `npx vite build --watch` to start both the build watcher and the preview server.
If your preview server is behind a reverse proxy, configure the `reload.clientPort` option in your `vite-live-preview` plugin settings to specify the correct port for the WebSocket client to connect to.