-
-
Notifications
You must be signed in to change notification settings - Fork 8.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
New watching solution #125
Comments
Very important 👍 Maybe witcher? 😉 |
Definitely interested in this, any updates? Watching seems a little broken right now for me :/ |
Well, actually it's not broken, but it behaves kind of weird. But as discussed in #122 it's not as easy as it may seem. |
No updates here. This is a very work intensive (and boring) task and my time is limited. The current solution is "ok" so this has a low prio. |
I can help with the name =] My suggestion: watchpack |
Nice 👍 |
Question: why aren't you using a watcher module that has already been built? I use chokidar for keeping files in sync between my windows shared folder in a vagrant Centos machine and a non-shared folder (the shared folder causes weird behavior, so i have to copy all the files somewhere else). Chokidar has been pretty robust in my experience. |
Interesting approach, I'm having issues with the shared folder as well. |
Well, if you need a head start, here's the utilities I wrote to help me create a watcher process: http://www.btetrud.com/files/fileWatcherUtils.js . Example: var windowsPathBase = '/vagrant'
var centosPathBase = "/home/vagrant/"+config.mainDirectory
var ignoreList = [/\.git/, /\.idea/, /\.vagrant/, /\.iml/, /Vagrantfile/, /CentOS-6.4-x86_64-v20130427.box/]
var ignore = function(path) {
var result = false
ignoreList.forEach(function(pattern) {
result = result || pattern.test(path)
})
return result
}
// windows -> centos
fileWatcherUtils.copyThenSync('/git', ignore, windowsPathBase, centosPathBase)
// centos -> windows
fileWatcherUtils.copyThenSync('/git/scripts/generated/', ignore, centosPathBase, windowsPathBase) |
Thx, I'll take a look! |
I'd also like to recommend using chokidar as it is pretty robust. I'm also using a shared vm folder and I've actually done a simple adhoc patch myself. In At the top Then around line 130
As you can see, I just changed the fs.watch to use chokidar.watch / watcher.on('change'). Didn't change anything else as I'm not sure what else should be changed. Just wanted a working solution for my development needs and it looks like its working. |
Does chokidar work with shared folders? Is chokidar supporting all requirements as described by sokra? Or are they obsolete @sokra ? |
I tried to implement a solution in chokidar, but it has some problems on windows... |
Another approach would be to use an external tool for file watching. You could completely remove file watching from webpack and instead allow incremental builds. As soon as something on disk changes the external tool could just call webpack again. For an example of an external file watching tool take a look at watchman (*nix only). It's extremely well-tested and so far doesn't consume a lot of cpu on my machine. (Another example: JetBrains WebStorm). So far all of the file watching features that are part of build tools and precompilers like grunt, gulp, webpack, browserify, coffeescript, less, etc. have disappointed me. This is an extremly hard problem to solve and I believe it should not be part of any build tool itself. Edit: I forgot to add why chokidar is not such a great solution at the moment. On OSX it depends on the fsevents module which isn't working anymore since Node 0.11.13 (still in beta, but it will become a problem once that node version becomes stable). The fsevents module was last updated 6 months ago. |
@JannesMeyer I like that idea a lot. Webpack's watcher has impressed me, but I think it would be good to factor it out so it can be used for other projects, or so that other watcher modules can be used in cases where webpack's watcher isn't sufficient. Separating it out would also open up other abilities to webpack. For example, if you did this right, someone could devise a way to save the webpack representation of its build state so that one could save it to disk, and use it in a new build that has some other method of figuring out which files have changed. This would require some way to externalize a representation of whatever state needs to exist to do incremental builds (if that info doesn't exist in the webpack bundle itself) and the ability to specify which modules changed that need to be rebundled. I doubt it'd be difficult to do, since its already done internally in webpack. |
@fresheneesz agreed 100%. I had the exact same thought :). This would be awesome. |
I've started a new library that should handle watching in the future, but I wasn't able to complete it yet. The design was to never watch files directly, but always watch the containing folder. This way the required watcher count is reduced. In addition to that multiple watchers on the same directory are merged to futher reduce the watcher count. The API allows to pause a Watcher, which doesn't close the internal watchers. This makes it cheap to restart the Watcher and allows to tell if there was an event in the past (which eliminates unnecessary recompilation). Currently I'm blocked by chokidar not working correctly... |
While better built-in watcher would be nice, I think it would be great if I could run a command to tell webpack which files have changed and then it can do the incremental rebuild that way. This would allow me to compose webpack with whichever watcher I like, such as watchman, simply piping lists of changed files to webpack. Something like I don't have any knowledge about how webpack internals work or what is involved in writing a good watcher, but it seems like this should be relatively straightforward to do compared to writing a watcher, and it would give people potentially better options while the built-in watcher is rebuilt. What do you think? |
@lencioni I'll check how we can add an API to support any watcher. chokidar issue seem to be fixed... |
We had a few problems with shared folders a while ago. Because of that we now use rsync with vagrant-gatling-sync and it works great. Of course, for one way syncing only. |
Yeah, I tried that, but I need two way syncing.... Luckly, I found unison, a sync tool via ssh. It works very fast, faster than rsync I guess.... Well, I'm using it and it's working 💃 Thanks for your answer! |
@EricPrieto If you're looking for perfect Vagrant dir sharing, try to share "current work dir" with 2 mount point - one for rsync and one for usual vboxsf. That gives just perfect workflow with file sharing... |
@EricPrieto Could you elaborate a bit on that? I'm pretty unhappy with way's I've found to do a shared folder in vagrant. Is there somewhere you could link to that describes that in more detail? I'll also have to look at unison - i built my own ad hoc watcher that's actually working pretty well at this point, but could be faster. |
@fresheneesz I documented how we install/use unison with vagrant manually: https://keylocation.sg/blog/vagrant-and-unison-without-a-plugin/ |
After a few weeks trying unison and every other solution, I just gave up. |
@EricPrieto As of webpack 1.9.10 you can use |
Awesome!
|
SpaceK33z, thanks. |
I found "--watch-polling" doesn't work. Instead I had to use "--watch-poll".... it's a small thing but nevertheless a source of confusion. I'm running webpack 1.11.0 and webpack-dev-server 1.10.1 |
@alanbacon Macbook pro late 2011 |
Hi i'm getting some strange behavior and don't know what is wrong, using webpack 2.0 on VM with Arch Linux, running Has some seen something similar? this is my config ( tried so many configuration but nothing helped ) and don't know if it's webpack or babel-loader problem ?
|
@piecyk you should ask this on SO, probably. Try to set larger watch timeouts:
It's in webpack-dev-server's config, please see more in docs |
@ColCh it's not a problem of timeouts, watch is working good till i hit the first |
@piecyk Try then inlude NoErrorsPlugin and specify babel-loader presets in webpack config also, as query (I had problems with .babelrc and latest loader version). If it will not help... I don't know. May be a bug also. |
From quick debug it looks like when file has error it's removed form the list of files to be watched, webpack/lib/node/NodeWatchFileSystem.js Line 17 in 9f440e3
here |
Old watching plugin or new, they both do not pick up on change events. When I run the watcher on OS X, all is fine. However, the reason we use a VM (through Vagrant) is to streamline the process. Bit of a bummer. Polling does not seem to work, either. |
VirtualBox's shared folder does not trigger change events, so this is not an issue of webpack (further discussion #425). I'm using |
@jhnns event get not triggered only with vboxfs or with NFS too? |
@ColCh Don't know |
@jhnns When the polling support in webpack also fails, it does make it a webpack problem |
Just moved to using a vagrant + NFS.
What could be the difference between the node API and the cli? its the only difference I can think of. |
Just read through all of this, and I must say that it would be great to remove the watcher from webpack entirely. Indeed, we could rely on external packages to watch for us if we get the incremental compilation right! It would reduce maintenance for the webpack team too, it's a win-win! |
I think having a plugin to watch external files is a better approach . How does this look ? https://www.npmjs.com/package/filewatcher-webpack-plugin . |
This is all very interesting. |
We have been using Webpack which has a built-in file watcher. When using the Webpack watcher along with overcommit, we were noticing that after every commit we were making, the compiled Webpack bundle would not contain the changes from that commit. By default, this watcher has a 200ms delay on file changes before it actually starts rebuilding, which is good enough for standard development. However, because of the way that overcommit plays with the working tree, our Webpack bundle was getting compiled without the changes from our most recent commit. This is happening because Webpack looks at the modified times of the files to determine if something has changed. If the modified time of the file is greater than the time that Webpack started watching, it registers as a change. Since overcommit is changing the modified times, this gets messed up. My theory is that the amount of time that elapses from the start of cleaning up the environment until the end of cleaning it up is greater than our Webpack watchDelay. We could probably resolve this by raising the watchDelay, but that slows down our standard development which I would prefer to avoid doing. Instead, it seems that if we restore the file modification times after every step when cleaning up the environment in overcommit, we can have a lower watchDelay without the negative side-effects described above. I do realize that this is not a full fix, but it should help. Webpack is currently working on building a new watcher [1], which may also resolve this issue for us, but I believe that this change will also likely benefit other file watchers. When restoring the modified times, we need to now make sure that the file exists because we are restoring after the working tree is cleared, so if the file is new, it will not exist (which will cause it to blow up). [1]: webpack/webpack#125 Change-Id: Ia28d6952bac5ef0d1ccac2276df2b62c46f11f68 Reviewed-on: http://gerrit.causes.com/44132 Tested-by: jenkins <jenkins@causes.com> Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
(see #122)
The watching implementation is far from perfect. Implement a new watching module and use it in webpack.
The new watching module should have to following properties:
pause
: Don't emit event anymore, but keep the watchers alive. When starting again less timestamps need to be read and less watchers need to be attached. This should make the whole stuff more stable.close
: Really close everything.persistant
option (because it is easy)UPDATE: Try it with:
The text was updated successfully, but these errors were encountered: