指向本地服务器访问时,webpack项目页面提示Invalid Host header.(无效的主机标头)

需要分两种情况解决,webpack4.0以下和webpack5.0

webpack4.0以下配置

//在webpack.dev.config.js文件devServer: {disableHostCheck: true,}

webpack5.0配置

在webpack 5 中disableHostCheck应该被遗弃了
查看文档了解到需将 disableHostCheck:true,替换为
historyApiFallback: true,
allowedHosts: “all”,

//webpack.dev.js文件devServer: {historyApiFallback: true,allowedHosts: "all",}