devServer的一些配置项
contentBase
运行代码的目录contentBase:resolve(__dirname,'build')
watchContentBase
监视ContentBase目录下的所有文件,一旦文件发生改变就会重载watchContentBase:true
watchOptions
监视文件watchOptions:{
//ignored,忽略某些文件,node_modules不需要监视
ignored:/node_modules/
}
compress
gzip压缩,把资源压缩得更小//启动gzip压缩
compress:true
port
服务器的端口号port:5000
host
域名host:'localhost'
open
自动打开浏览器open:true
hot
模块热更新功能,HMRhot:true
clinetLogLeve
服务器日志clinetLogLeve:'none'//none为不显示服务器日志
quiet
不打印除了基本的启动信息以外的信息quiet:true
overlay
如果出错不要全屏提示overlay:false
proxy
代理服务器,解决开发环境跨域问题proxy:{
'/api':{
target:'http//:localhost:3000',
pathRewrite:{
'^/api':''
}
}
}
target:
一旦devServer(5000)服务器接收到/api/xxx的请求,就会把请求转发到http//:localhost:3000这个服务器
pathRewrite:
转发请求时,将请求路径重写:将/api/xx改成/xxx/ (去掉/api)