Search code examples
webpackmigrationwebpack-dev-serverwebpack-5

What is the replacement for `watchOptions` in webpack-dev-server v4.15?


I am migrating to webpack-dev-server v4.15, I got following error:

Options has an unknown property 'watchOptions".

When I checked the official migration doc, it mentioned that, watchOptions has been moved to static property. Could anyone please help me to understand exactly which property (directory, staticOptions, publicPath, serveIndex, watch) from static object is representing watchOptions now.

Let say if currently I have:

watchOptions: { ignored: ignoredFiles(/node_modules/)

So with which option I should use ignoredFiles now?

Any amount of help will be really appreciated. Thanks.


Solution

  • The static.watch configuration is the replacement for watchOptions, see v4.15.1/lib/Server.js#L914

    devServer: {
        static: {
          watch: {
            ignored: /node_modules/,
          },
        },
    },
    

    WDS uses chokidar package to handle the file watch. You can find the ignore configuration of it. It accepts a regexp.