Skip to content
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

watchOptions.ignored not working #1208

Closed
1 of 3 tasks
websolutions-hamburg opened this issue Nov 30, 2017 · 12 comments
Closed
1 of 3 tasks

watchOptions.ignored not working #1208

websolutions-hamburg opened this issue Nov 30, 2017 · 12 comments

Comments

@websolutions-hamburg
Copy link

websolutions-hamburg commented Nov 30, 2017

  • Operating System: Windows 10
  • Node Version: 9.2.0
  • NPM Version: 5.5.1
  • webpack Version: 3.8.1
  • webpack-dev-server Version: 2.9.5
  • This is a bug
  • This is a feature request
  • This is a modification request

Code

  devServer: {
      contentBase: path.join(__dirname, 'dist'),
      watchContentBase: true,
      watchOptions: {
        ignored: '/\*\*\/*.html/' // or /\*\*\/*.html/ or '**/*.html'
      }
  }

Expected Behavior

Ignore all *.html files.

Actual Behavior

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.

For Bugs; How can we reproduce the behavior?

Start the dev-server with option watchContentBase and try to ignore watch some files from the content base.

@shellscape
Copy link
Contributor

@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 e7c5452 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.

@shellscape
Copy link
Contributor

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

@jaunkst
Copy link

jaunkst commented Dec 1, 2017

watchOptions isn't ignoring anything at all. We have a file that is generated before compile time and its triggering another recompile unfortunately.

@shellscape
Copy link
Contributor

@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

@jaunkst
Copy link

jaunkst commented Dec 4, 2017

@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.

  1. We are generating an entry file before we are kicking off the webpack-dev-server
  2. The watchpack has a 10s look behind on file changes and it is triggering the second build
  3. The watchOptions.ignore doesn't seem to allow us to ignore files that are entry items

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.

@shellscape
Copy link
Contributor

@jaunkst lots of solid info there. but I'm really confused - who is "we"? do you work with the original post author?

@jaunkst
Copy link

jaunkst commented Dec 5, 2017

@shellscape I do not work with the original author. I was referring to my team, sorry for the confusion.

@shellscape
Copy link
Contributor

@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.

@jaunkst
Copy link

jaunkst commented Dec 5, 2017

@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.

@shellscape
Copy link
Contributor

Waiting on CI to confirm the build and will publish when that's done running.

@baerrach
Copy link

baerrach commented Jul 3, 2019

@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 webpack/watchpack#25 "Files created right before watching starts make watching go into a loop"

And solved it with https://github.com/egoist/time-fix-plugin

@nickveliki
Copy link

I solved it with
watchOptions:{
ignored: new RegExp("node_modules")
}
but with any format of string suggested in the manual it didn't work

Linux Ubuntu 20.04.2
webpack 4.41.5
chokidar 3.5.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants