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

Server Watch additional files #14570

Closed
4 tasks done
djibarian opened this issue Oct 10, 2023 · 4 comments
Closed
4 tasks done

Server Watch additional files #14570

djibarian opened this issue Oct 10, 2023 · 4 comments

Comments

@djibarian
Copy link

Description

Currently server.watch option allows passing options to chokidar. Docs state that the glob can be negated for a node_module to be included, but it doesn't seem to be working for other files which were not previously excluded.

For example, I want to cause a plugin to be called whenever a file /config.json is changed, because that plugin generates an in-memory new json which the app consumes. Ideally that would trigger a reload, like when modifying vite.config.ts.

Trying the following doesn't work, and because the included files are not part of the chokidar options, it looks that there is no way to watch for additional files:

server: {
  watch: {
    ignored: ['!/config.json']
  }
}

Suggested solution

Make the previous negated ignored globs functional or add a new include options to server.watch.

Alternative

No response

Additional context

No response

Validations

@sapphi-red
Copy link
Member

For that case, you can use this.addWatchFile.

@djibarian
Copy link
Author

Can't get it to work. Is any other thing, apart from calling this.addWatchFile(), to add to vite's config?

@sapphi-red
Copy link
Member

sapphi-red commented Oct 11, 2023

Would you create a reproduction?

@djibarian
Copy link
Author

Can't. But wouldn't be this the only needed thing? I spent a lot of time yesterday googling and trying lots of different permutations of the below and couldn't see any other thing that this one, but it doesn't work. My concern is if Vite is stopping this to work in some way, because all the stuff I've found on the internet was related to Rollup, not Vite.

buildStart(){
  this.addWatchFile(path.resolve(
    __dirname,
    'config.json'
  ))
  this.addWatchFile(path.resolve(
    __dirname,
    'app/src/config/config.template.json'
  ))
},

@github-actions github-actions bot locked and limited conversation to collaborators Oct 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants