我正在使用webpack/react-starter,我试图使用与我的开发机器连接到同一LAN的移动设备进行测试。因此,不要将localhost:3000放入我的移动浏览器中,而是将IP 192.168.X.X:3000。手机上的webpack-dev-server测试
这是什么最佳实践,因为手机不知道能够评估本地主机的脚本标记?我把这个hacky脚本放在开发中的html中,但这种感觉是错误的。
<script>
//inserts new script tag with localhost replaced by ip
if('ontouchstart' in window){
var ipRegex = /([0-9]{3}\.){2}[0-9]{1,3}\.[0-9]{1,3}/;
var ip = window.location.href.match(ipRegex)[0];
var url = Array.prototype.shift.call(document.getElementsByTagName('script')).getAttribute('src');
var newScript = document.createElement('script');
newScript.src=url.replace('localhost',ip);
document.body.appendChild(newScript);
}
</script>
此取下来的包,但socket.io无法连接到的WebPack-DEV-服务器[Error] Failed to load resource: Could not connect to the server. (socket.io, line 0)
,不会让我使用HMR。普通人在这种情况下做什么?