Skip to content
Projets

antfu/vite-plugin-restart

Voir sur GitHub

À propos

Custom files/globs to restart Vite server

Outils de développement

Comment ces chiffres sont mesurés

Progression mesurée des étoiles

in 24h
0
in 7 days
0
in 15 days
-1
in 1 month
Historique en cours

Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.

README.md

Original

vite-plugin-restart

Custom files/globs to restart Vite server



Usage

Install

npm i vite-plugin-restart -D # yarn add vite-plugin-restart -D

Add it to vite.config.js

// vite.config.js
import ViteRestart from 'vite-plugin-restart'

export default {
  plugins: [
    ViteRestart({
      restart: [
        'my.config.[jt]s',
      ]
    })
  ],
}

Changes to my.config.js or my.config.ts will now restart the server automatically.

Options

export interface VitePluginRestartOptions {
  /**
   * Enable glob support for watcher (it's disabled by Vite, but add this plugin will turn it on by default)
   * @default true
   */
  glob?: boolean
  /**
   * Delay in ms before restarting the server
   * @default 500
   */
  delay?: number
  /**
   * Array of files to watch, changes to those file will trigger a server restart
   */
  restart?: string | string[]
  /**
   * Array of files to watch, changes to those file will trigger a client full page reload
   */
  reload?: string | string[]
  /**
   * Enable content-based change detection to prevent unnecessary restarts
   * when file metadata changes but content remains the same
   * @default true
   */
  contentCheck?: boolean
}

Content-Based Change Detection

By default, the plugin now uses content-based change detection (contentCheck: true). This prevents infinite restart loops when watching auto-generated files that may be rewritten with the same content.

For example, when watching .eslintrc-auto-import.json:

export default {
  plugins: [
    ViteRestart({
      restart: [
        '.eslintrc-auto-import.json',
      ],
      // Content check is enabled by default
      // Only restarts if file content actually changes
      contentCheck: true,
    })
  ],
}

The plugin calculates a SHA-256 hash of the file content and only triggers a restart if the hash changes. This solves the problem of:

  • Auto-generated files being rewritten during the build process
  • File modification timestamps changing without actual content changes
  • Infinite restart loops caused by files being regenerated on every server restart

You can disable this feature if needed:

export default {
  plugins: [
    ViteRestart({
      restart: ['my.config.js'],
      contentCheck: false, // Disable content-based detection
    })
  ],
}

Motivation

Byebye nodemon -w my.config.js -x 'vite'

License

MIT License © 2021 Anthony Fu

Explorer des projets similaires

Chargement…