webpack dev server 无法通过ip访问问题

本文介绍了解决前端项目中Webpack-dev-server仅限本地访问的问题。通过设置--host 0.0.0.0使服务器接受来自局域网的请求,并提供如何查找本机IP地址的方法,最终实现跨设备访问。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

同事开发前端项目,通过webpack-dev-server起的服务,本地localhost:300正常访问,而同一个局域网内其他同事无法通过她机器ip访问。


解决方法:

(If you're on a Mac and network like mine.)

Run webpack-dev-server with --host 0.0.0.0 — this lets the server listen for requests from the network, not just localhost.

Find your computer's address on the network. In terminal, type ifconfig and look for the en1section or the one with something like inet 192.168.1.111

In your mobile device on the same network, visit http://192.168.1.111:8080 and enjoy hot reloading dev bliss.


参考:https://stackoverflow.com/questions/35412137/how-to-get-access-to-webpack-dev-server-from-devices-in-local-network

https://github.com/webpack/webpack-dev-server/issues/147

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值