1、修改 config/index.js 的 host 属性为 '0.0.0.0'
// Various Dev Server settings
host: '0.0.0.0', // can be overwritten by process.env.HOST
port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: false,
errorOverlay: true,
notifyOnErrors: true,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
2、修改 build/webpack.dev.conf.js 的 devServer 配置
增加 disableHostCheck = true
devServer: {
clientLogLevel: 'warning',
historyApiFallback: {
rewrites: [
{ from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') },
],
},
hot: true,
contentBase: false, // since we use CopyWebpackPlugin.
compress: true,
host: HOST || config.dev.host,
port: PORT || config.dev.port,
open: config.dev.autoOpenBrowser,
overlay: config.dev.errorOverlay
? { warnings: false, errors: true }
: false,
publicPath: config.dev.assetsPublicPath,
proxy: config.dev.proxyTable,
quiet: true, // necessary for FriendlyErrorsPlugin
disableHostCheck: true,//ljj add
watchOptions: {
poll: config.dev.poll,
}
},
3、如果还是不能访问,检查防火墙
本人用的是Centos7,8080端口也添加了,经过上述操作修改之后还是不能访问,遂systemctl stop firewalld,启动后就能通过IP访问了。