webpack devserver

穆才良
2023-12-01

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
模块热更新功能,HMR
hot: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)

 类似资料:

相关阅读

相关文章

相关问答