問題:
在 webpack.config.js 配置了devServer,通過contentBase 配置了靜態(tài)資源的路徑,但是報錯了。報錯如下:文章來源:http://www.zghlxwxcb.cn/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
文章來源地址http://www.zghlxwxcb.cn/news/detail-842475.html
const path = require('path')
module.exports = {
mode: "development", // 指定構(gòu)建模式
entry: "./src/main.js", // 指定構(gòu)建入口文件
output: {
path: path.resolve(__dirname, 'main'), // 指定構(gòu)建生成的文件名
filename: "build.js" // 指定構(gòu)建生產(chǎn)的文件名
},
devServer: {
static: path.resolve(__dirname, 'dist') // 開發(fā)服務(wù)器啟動路徑
}
}
到了這里,關(guān)于[webpack-cli] Invalid options object. Dev Server has been initialized using an options object that d的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!