vite-plugin-restart is a Vite development server plugin that allows developers to define custom files or glob patterns whose changes trigger an automatic restart of the Vite server or a client-side full page reload. This eliminates the need for manual server restarts when modifying configuration files, database schemas, or other non-hot-reloadable assets, often replacing external watchers like `nodemon`. The package is currently stable at version `2.0.0` and typically releases updates to maintain compatibility with new Vite major versions and introduce features or bug fixes. A key differentiator introduced in v2.0.0 is content-based change detection, which, by default, prevents unnecessary restarts caused by file metadata changes or infinite loops when watching auto-generated files. It also offers a `delay` option to debounce restart triggers.
npm install vite-plugin-restartVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to configure `vite-plugin-restart` in `vite.config.ts` to automatically restart the Vite development server when specified configuration files (like `my.config.ts`) change, or trigger a full client-side reload for other file types. It showcases the `restart`, `reload`, and `delay` options.
Ensure your `vite.config.js` is set up for ESM (e.g., using `import` statements, or renaming to `vite.config.mjs`).
If specific edge cases require restarting on metadata-only changes, set `contentCheck: false` in the plugin options. Otherwise, no action is needed as this is the new default behavior.
Ensure `contentCheck: true` (default since `v2.0.0`) or carefully select files that do not cause circular dependencies for restarts. Consider using the `delay` option to debounce restarts for slower systems.
Update your `vite.config.js` to use ESM `import` statements. If you're encountering issues with your environment's ESM support, consider renaming `vite.config.js` to `vite.config.mjs`.
Ensure `contentCheck: true` is enabled (it's the default since `v2.0.0`). This feature only triggers restarts if file content changes. If the issue persists, carefully review your `restart` array to exclude files that are frequently rewritten or disable `contentCheck` and add a sufficiently large `delay`.