如何隐藏"Download the React DevTools for a better development experience:"



每次我启动或重新加载我的react应用程序时,我都会收到相同的控制台日志消息"**下载react DevTools以获得更好的开发体验:https://reactjs.org/link/react-devtools**"

如何禁用此消息,以便在部署站点时看不到该消息?

控制台日志映像

我找到了关于这个问题的其他帖子,但是没有解决办法。

一旦你对React应用程序进行了产品构建,控制台日志将不会被打印出来。只有当您在开发模式下运行它时才会看到它。

如果你使用的是React+Vite,那么进入文件位置:"node_modules/.vite deps/react-dom_client.js"

然后删除行:


if (/^(https?|file):$/.test(protocol)) {
console.info("%cDownload the React DevTools for a better development experience: https://reactjs.org/link/react-devtools" + (protocol === "file:" ? "nYou might need to use a local HTTP server (instead of file://): https://reactjs.org/link/react-devtools-faq" : ""), "font-weight:bold");
}

如果你不使用vite,那么就在node.js中搜索所有文件:

"下载React DevTools获得更好的开发体验">

你会找到一个匹配的,然后删除代码

最新更新