'Ignore coverage HTML files from Vite + React HMR

I have a project set up using vite with the @vitejs/plugin-react extension. I'm using the basic config of

export default defineConfig({
  plugins: [react({ include: ['src'] })]
})

In the dev server output I'm seeing page reloads of my coverage HTML files, for example

8:09:45 PM [vite] page reload coverage/lcov-report/App.tsx.html

My coverage files are located in the project root with a directory of coverage. I've tried a number of settings in the Vite config, such as

optimizeDeps: {
  entries: ['index.html'],
  exclude: ['coverage']
}

and

server: {
  watch: {
    exclude: ['coverage']
  }
}

however neither of these seem to have any effect. I also tried the following on the React plugin itself

exclude: /coverage/

but no dice. I would expect that a path like coverage would be excluded by default.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source