Watch mode
Is your feature request related to a problem? Please describe.
It would be nice to run this in "watch mode" where it runs a build automatically when files change.
Describe the solution you'd like
yarn build --watch adds file watchers for the folders that it considers inputs and if it detects a change it runs a build (after some debounce / stability time).
Describe alternatives you've considered
Probably can cook something up using nodemon, where it just watches everything and runs yarn build if anything changes. Since yarn build doesn't do anything unless an interesting file has actually changed, it should work.
I’ve played with this idea a bit, and it was hard to generalise without adding too much configuration. Some scripts want to run in their own watch modes (nextjs for example).
Though, we did recent merge a PR which could help #146, specifically with being able to do something like yarn build "@scope/*".
Adding a file watcher is also slightly tricky as they can consume a surprising amount of resources in big projects, which is where yarn.build shines. Facebook’s watchman is a good example of how it’s often solved (having one server watch, and heaps of clients listening), though I find it nearly impossible to understand.
I do think adding a watcher could be great, and that it fits reasonably naturally into where yarn.build is in this space of dev tools.
In the mean time using any file watcher including nodemon to call yarn.build should work — though it may mangle the output. Keen to hear how it goes.
A way I've worked around this is using rollup --watch. I just manually set the build command ie yarn build --build-command rollup --watch --interlaced --verbose --ignore-cache.
Thank goodness for the CLI helpers otherwise I wouldn't have known --build-command was an option!
We will be implementing this using watchman, let me know if you're interested in the final solution. watchman is not that difficult 🙂