devServer: {
contentBase: path.join(__dirname, 'dist'),
watchContentBase: true,
watchOptions: {
ignored: '/\*\*\/*.html/' // or /\*\*\/*.html/ or '**/*.html'
}
}
Ignore all *.html files.
Nothing will be ignored. I also checked the source code from webpack and webpack-dev-server and I didn't found a place where the configuration watchOptions.ignored will be used.
Start the dev-server with option watchContentBase and try to ignore watch some files from the content base.
@websolutions-hamburg thanks for the report, and good catch. I went all the way back through the blame and couldn't figure out when these options were ever used. this commit e7c54525badeee77b3ae19b6a5bd234b4e4fc64f seems to have added the option. It would appear that these are supposed to be used with the chokidar module, which WDS makes use of, but there are some discrepancies. I'll have to get with the team to chat about it and get back to you.
OK so webpack proper is using an org module called watchpack, which is massaging the options before it's passed to chokidar https://github.com/webpack/watchpack/blob/ebcdc813100168af1a61189403a8b1abfa5338a3/lib/DirectoryWatcher.js#L58
That's a hold-over from before the project started using chokidar. So we're going to have to update the docs for WDS, and also do the same massaging of options here in WDS (in addition to actually passing the options to chokidar)
So there's some work to be done
watchOptions isn't ignoring anything at all. We have a file that is generated before compile time and its triggering another recompile unfortunately.
@jaunkst are you joining this issue to comment on a possibly-related issue, or the same symptoms in a different project? please remember it's best to be verbose.
watchOptions isn't ignoring anything at all.
in this context that's not actually true
@shellscape I have looked deeper and have discovered what our issue was, and how to work around it. I think its a combination of a few things.
We are currently having to backdate the file when its generated.
So I think the issue is with watchpacks 10s backdate window. The idea of ignoring a file that is added to webpacks entries does seem weird but in our case it is an autogenerated index.
I was somewhat confused as to what was actually going on and assumed that somehow the ignored rule wasn't being applied.
Anyways, I never got the ignore rule to actually work in this particular case and I realize that in this issue it is when watching the baseContent for changes.
@jaunkst lots of solid info there. but I'm really confused - who is "we"? do you work with the original post author?
@shellscape I do not work with the original author. I was referring to my team, sorry for the confusion.
@jaunkst thanks for clarifying. wanted to make sure I was addressing folks the right way here. Given your discoveries, I think it would be prudent to take this issue up with watchpack first, and webpack second. That is of course, if watchOptions is defined in your webpack.config.js. The other issue we have related to this issue is what I mentioned about the watchOptions not being passed through to chokidar within webpack-dev-server (the commit I linked to) - and that has to be resolved as well.
@shellscape yep, thats what I was thinking. I ended up logging the onChanges event in watchpack to see what files where triggering the recompile. It was the generated file and add adding it to the watchOptions.ignored did nothing. I even tried passing the options down to webpack-dev-servers watch options as you mentioned and it didn't help either. So I am assuming that because it is an entry it isn't being ignored or another watcher is being applied to the entries.
Waiting on CI to confirm the build and will publish when that's done running.
@jaunkst Google brings me here with the same problem as you.
I'm a webpack newbie so I'm not sure generating the file is the correct solution to the problem.
Could you add a comment to indicate where the discussion continues or how you solved it for future searchers?
After much searching I found the problem to be https://github.com/webpack/watchpack/issues/25 "Files created right before watching starts make watching go into a loop"
And solved it with https://github.com/egoist/time-fix-plugin