问题:
在 webpack.config.js 配置了devServer,通过contentBase 配置了静态资源的路径,但是报错了。报错如下:文章来源:https://www.toymoban.com/news/detail-842475.html
[webpack-cli] Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options has an unknown property 'contentBase'. 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?, setupMiddlewares?, static?, watchFiles?, webSocketServer? }
原因及解析:
错误信息中提示contentBase 不是有效的配置项(可以看到contentBase不在罗列的有效配置项中)。因为Weback 5 将 contentBase的配置修改为 static
解决
把 contentBase
改为 static
文章来源地址https://www.toymoban.com/news/detail-842475.html
const path = require('path')
module.exports = {
mode: "development", // 指定构建模式
entry: "./src/main.js", // 指定构建入口文件
output: {
path: path.resolve(__dirname, 'main'), // 指定构建生成的文件名
filename: "build.js" // 指定构建生产的文件名
},
devServer: {
static: path.resolve(__dirname, 'dist') // 开发服务器启动路径
}
}
到了这里,关于[webpack-cli] Invalid options object. Dev Server has been initialized using an options object that d的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!