Skip to content

watchOptions.ignored not working #1208

Description

@websolutions-hamburg
  • 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.

Activity

  1. shellscape commented on Nov 30, 2017

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

  2. shellscape commented on Nov 30, 2017

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

  3. loops-and-spells commented on Dec 1, 2017

    @loops-and-spells

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

  4. shellscape commented on Dec 4, 2017

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

  5. loops-and-spells commented on Dec 4, 2017

    @loops-and-spells

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

  6. shellscape commented on Dec 5, 2017

    @shellscape
    Contributor

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

  7. loops-and-spells commented on Dec 5, 2017

    @loops-and-spells

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

  8. shellscape commented on Dec 5, 2017

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

  9. loops-and-spells commented on Dec 5, 2017

    @loops-and-spells

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

  10. shellscape commented on Dec 6, 2017

    @shellscape
    Contributor

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

  11. baerrach commented on Jul 3, 2019

    @baerrach

    @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

  12. nickveliki commented on Sep 16, 2021

    @nickveliki

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions