oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.28k stars 2.77k forks source link

Include/exclude config for `bun run --watch` #5278

Open timnghg opened 1 year ago

timnghg commented 1 year ago

What is the problem this feature would solve?

I would like to propose improvements to the bun run --watch command in order to make it more versatile and applicable to a wider range of use cases.

E.g. prevent hard/soft restart when tsx files changed.

What is the feature you are proposing to solve the problem?

Include/exclude glob config for watch mode

1. bunfig.toml

[watch]
excludes = ["**/*.tsx"]
includes = ["**/*.ts"]

2. CLI

bun run --watch --watch-includes=**/*.ts --watch-excludes=**/*.tsx

What alternatives have you considered?

oliverjam commented 1 year ago

Yeah Bun's hot-reloading would be amazing if we could reload on HTML/CSS/markdown etc changes, rather than just JS in the module graph. I've got a websocket-based browser reload mechanism working, but it doesn't trigger when the files that matter change 😅

Deno's --watch flag supports passing a list of paths to watch (although this doesn't appear to be in the docs it is in --help).

--watch[=<FILES>...]
  Watch for file changes and restart process automatically.
  Local files from entry point module graph are watched by default.
  Additional paths might be watched by passing them as arguments to this flag.
jens-ox commented 1 year ago

I'm using Fastify and Vite for a new project. bun --watch index.ts (or bun --hot index.ts) doesn't work currently, as Vite will re-generate files during the execution of index.ts, causing bun to reload in a loop.

Having the possibility to exclude files from being watched would solve this imo.

trya2l commented 1 month ago

Hi, are there any interest about this issue ? Basically I'm at the same as @jens-ox, this would allow full hot reload capability with SSR

oliverjam commented 1 month ago

As of v1.1.27 Bun will hot-reload on arbitrary file changes if you import them

https://bun.sh/blog/bun-v1.1.27#watch-arbitrary-file-types-in-watch-and-hot

It would still be nice to be able to exclude files from the watcher though