-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
feat(cli): build watch mode #1449
Conversation
Could we get this faster? Maybe defer reloading the config file to a separate follow-up pull request? |
I think this will be the way I will follow, introducing a watcher for The caveat is that updated plugins will not trigger rebuild ... and that one of the main goal of this functionality Maybe we can create a custom @yyx990803 where I can add related tests for that functionality ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Havn't tested it, but code looks okay to me 🙂
We may await additional reviews from e.g. core members
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works great!
As @Shinigami92 suggested, we should add the -w
option as webpack does.
Also, it would be nice to add line breaks so the output looks like
vite v2.1.2 building for production...
watching for file changes...
✓ 18 modules transformed.
And it is easier to see that we are in watch mode
There should also be an extra break line between build outputs so it is easy to identify each one.
Current output:
λ yarn build --watch
yarn run v1.22.10
$ vite build --watch
vite v2.1.2 building for production...
watching for file changes...
✓ 18 modules transformed.
dist/index.html 0.16kb
dist/assets/index.cef4026c.js 2.49kb / brotli: 0.75kb
dist/assets/vendor.ebcc162a.js 196.17kb / brotli: 41.34kb
built in 1650ms.
Note: Using vite preview
I was not able to reload the page after the re-build. Do you know why this is happening? I tried with serve
and it works correctly.
Would be great if this was able to push the updated files to the browser also, in the same way that Snowpack does. Besides watching files and building them, it also spins up a small node web server through which it pushes updates to the browser via websockets. In development builds, it injects a small bit of JS into the build which connects to the local node server to receive those updates. Works really well. Just a thought... |
I improved the output and added the
The main goal of the two commands are different: |
Great! Thanks for taking care of that details 👍🏼 I meant that reloads works using https://www.npmjs.com/package/serve, but it doesn't reload correctly using |
Thanks a lot for implementing this feature @stafyniaksacha 🙌🏼 |
@stafyniaksacha How to use it programmatically? In my project I run const {build} = require('vite')
customFileWatcher(() => build({mode, configFile: 'path/to/vite.config.js'}) ) It's not very obvious to me how to programmatically run a build and file watcher after this PR. |
hi @cawa-93 this should do the tricks: const { build } = require('vite')
const config = {
mode,
configFile: 'path/to/vite.config.js',
build: {
/**
* Rollup watch options
* https://rollupjs.org/guide/en/#watchoptions
*/
watch: {}
}
}
customFileWatcher(() => build(config) ) |
}) | ||
|
||
// stop watching | ||
watcher.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is close
called immediately?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this close
call is a no-op. Is this line accidental?
See here:
https://github.com/rollup/rollup/blob/dba6f13132a1d7dac507d5056399d8af0eed6375/src/watch/watch-proxy.ts#L16
https://github.com/rollup/rollup/blob/dba6f13132a1d7dac507d5056399d8af0eed6375/src/watch/watch-proxy.ts#L31-L33
https://github.com/rollup/rollup/blob/dba6f13132a1d7dac507d5056399d8af0eed6375/src/watch/watch.ts#L47
Add build watch mode (through rollup)
See #1434
Enable watch mode
cli
vite.config.ts
Todo
vite.config.ts
reload