[webpack-cli] Invalid options object. Dev Server has been initialized using an options object that d

问题:
webpack.config.js 配置了devServer,通过contentBase 配置了静态资源的路径,但是报错了。报错如下:

[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?, ***press?, 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

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') // 开发服务器启动路径
    }
}
转载请说明出处内容投诉
CSS教程_站长资源网 » [webpack-cli] Invalid options object. Dev Server has been initialized using an options object that d

发表评论

欢迎 访客 发表评论

一个令你着迷的主题!

查看演示 官网购买