Webpack 开发服务器无法将 watchContentBase 识别为有效选项。
watchContentBase
是否已弃用?如果是这样,有什么替代方案?以下是我的 Webpack 开发服务器的配置:
devServer: {
contentBase: path.resolve(__dirname, 'dist'),
port: 8080,
open: true,
hot: true,
watchContentBase: true,
}
当我运行服务器时,出现以下错误。
无效的选项对象。开发服务器已使用初始化 选项对象与 API 模式不匹配。
- options 有一个未知属性“watchContentBase”。这些属性是有效的: object { allowedHosts?, bonjour?, client?, 压缩?,devMiddleware?,标头?,historyApiFallback?,主机?,热?, http2?、https?、ipc?、liveReload?、magicHtml?、 onAfterSetupMiddleware?、onBeforeSetupMiddleware?、onListening?、 打开?、端口?、代理?、服务器?、setupExitSignals?、静态?、 watchFiles?,webSocketServer? }
在新版本中
devServer:{
static: path.resolve(__dirname, 'src'),
port: 8080,
open: true,
hot: true
}
只需将
contentBase
重命名为 static
。
如果您使用 webpack-dev-server,则默认启用 watch。话虽如此,您可以删除 watchContentBase: true,就像 Kamran 上面显示的那样。
devServer: {
static: path.resolve(__dirname, 'src'),
port: 8080,
open: true,
hot: true
}
[电子邮件受保护] 中的静态选项。并且它们不再可用。
有关更多详细信息,请阅读迁移指南:https://github.com/webpack/webpack-dev-server/blob/master/migration-v4.md