简体   繁体   English

在运行时禁用 create-react-app webpack hot/live reload

[英]Disable create-react-app webpack hot/live reload at runtime

I'm trying to do some before/after comparisons of my React code in two different tabs/windows, but the hot/live reload feature of create-react-app/webpack is preventing me from running old/new code side-by-side.我正在尝试在两个不同的选项卡/窗口中对我的 React 代码进行一些之前/之后的比较,但是 create-react-app/webpack 的热/实时重新加载功能阻止我并排运行旧/新代码-边。

The previously accepted solution of using DevTools request blocking the websocket connection with localhost:3000/sockjs-node/* no longer seems to work (on Chrome 86).以前接受的使用DevTools 请求阻止 websocket 连接localhost:3000/sockjs-node/*解决方案似乎不再有效(在 Chrome 86 上)。

I figured out that the hot/live reload feature calls a global function called webpackHotUpdate which I could override to disable the functionality.我发现热/实时重新加载功能调用了一个名为webpackHotUpdate的全局函数,我可以覆盖它以禁用该功能。

Run in DevTools console在 DevTools 控制台中运行

window.webpackHotUpdate = () => {}

Note: this does not disable the display of compile errors/warnings which gets sent through the websocket connection.注意:这不会禁用通过 websocket 连接发送的编译错误/警告的显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM