Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to disable watch in vite CLI #19188

Open
4 tasks done
jpilgrim opened this issue Jan 12, 2025 · 2 comments
Open
4 tasks done

Add option to disable watch in vite CLI #19188

jpilgrim opened this issue Jan 12, 2025 · 2 comments

Comments

@jpilgrim
Copy link

Description

As a developer I want vite CLI to have an option to disable watch so that I when I start a server (via vite dev) for testing purposes, the server does not start again if changed in the root are detected (due to written test results).

That is, I use npm run dev to start a server, and then I use frontend tests (in my case Selenium for some special reasons). The tests produce some output, e.g. coverage and other stuff. This causes the server to restart.

I only want to deactivate the watch when running tests, so I still want to use watch in normal development mode.
Creating a second config file is a bit troublesome, I really would prefer a CLI option.

Suggested solution

Add option
--disableWatch
(or --watch=null)
to CI tool vite

Alternative

No response

Additional context

This feature request is related to #8341 (which wants to limit the watcher)

Validations

@hi-ogawa
Copy link
Collaborator

Creating a second config file is a bit troublesome,

I'm not sure what you mean by a second config. Switching server.watch manually from env var can be a quick alternative. https://stackblitz.com/edit/vitejs-vite-vqrkhbxj?file=vite.config.ts

import { defineConfig } from 'vite';

export default defineConfig({
  server: {
    // then run 
    //  DISABLE_WATCH=1 vite dev
    watch: process.env.DISABLE_WATCH ? null : undefined,
  },
});

@bluwy
Copy link
Member

bluwy commented Jan 13, 2025

Disabling watch is not very common when running vite dev, so I'm not sure if it's worth a new option here. Is there reason also you're testing your app against the dev server? Shouldn't it be the built preview server? The build output is able to generate optimized assets that can load certain things faster, which would be more stable for e2e tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants