devServer的一些配置项
contentBase:resolve(__dirname,'build')
watchContentBase:true
watchOptions:{
//ignored,忽略某些文件,node_modules不需要监视
ignored:/node_modules/
}
//启动gzip压缩
compress:true
port:5000
host:'localhost'
open:true
hot:true
clinetLogLeve:'none'//none为不显示服务器日志
quiet:true
overlay:false
proxy:{
'/api':{
target:'http//:localhost:3000',
pathRewrite:{
'^/api':''
}
}
}
target:
一旦devServer(5000)服务器接收到/api/xxx的请求,就会把请求转发到http//:localhost:3000这个服务器
pathRewrite:
转发请求时,将请求路径重写:将/api/xx改成/xxx/ (去掉/api)