Webpack dev server does not recognize watchContentBase as valid option

Viewed 4625

Webpack dev server does not recognize watchContentBase as a valid option. Is watchContentBase deprecated? If so what is the alternative? Below is the configuration of my Webpack dev server:

devServer:{
    contentBase: path.resolve(__dirname, 'dist'),
    port: 8080,
    open: true,
    hot: true,
    watchContentBase: true,
}

When I run my server, I get the following error.

Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.

  • options has an unknown property 'watchContentBase'. These properties are valid: object { allowedHosts?, bonjour?, client?, compress?, devMiddleware?, headers?, historyApiFallback?, host?, hot?, http2?, https?, ipc?, liveReload?, magicHtml?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, port?, proxy?, server?, setupExitSignals?, static?, watchFiles?, webSocketServer? }
4 Answers

In the newer version

devServer:{
    static: path.resolve(__dirname, 'src'),
    port: 8080,
    open: true,
    hot: true
}

Just rename contentBase to static.

If you're using webpack-dev-server, watch is enabled by default. That being said, you can remove watchContentBase: true, just like Kamran shows above.

devServer: {
    static: path.resolve(__dirname, 'src'),
    port: 8080,
    open: true,
    hot: true
}
Related