如何在Create React App中不显示警告 [英] How to not show warnings in Create React App
问题描述
我正在使用来自Facebook的create-react-app,当它通过"npm start"启动时,会显示警告列表,例如:
I'm using create-react-app from Facebook, when it starts via 'npm start' it shows me a list of warnings, such as:
'Bla'已定义但从未使用过
应该是'===',而是看到了'=='
'Bla' is defined but never used
Expected '===' and instead saw '=='
我不想看到任何这些警告,有没有办法抑制它们?
I don't want to see any of these warnings, is there a way to supress them?
推荐答案
对于本地Eslint,将文件添加到名为 .eslintignore
的项目中,并添加任何要忽略的目录或文件:>
For local Eslint, add a file to your project named .eslintignore
and add any directories or files you want to ignore:
build/
src/
*.js
尽管您现在最好将其完全删除.
Though you might as well remove it entirely at this point.
但是,如果您使用的是 create-react-app
,则这不适用于构建或启动代码.无法将Eslint禁用而不退出,因为它是内置在react-scripts中的.每当您构建或启动服务器时,除 package.json
中定义的特殊情况外,它将使用其内部配置运行eslint.唯一的解决方法是弹出或在每个文件前面添加禁用注释,如其他地方所述.有关更多信息,请参见在Github上的此问题.
This doesn't work with building or starting the code however, if you are using create-react-app
. There is no way to disable Eslint without ejecting because it's built into react-scripts. Anytime any you build or start the server, it will run eslint using its internal configs aside from special cases defined in package.json
. The only way around that is to eject or prepend each file with the disable comment as mentioned elsewhere. See this issue on Github for more information.
这篇关于如何在Create React App中不显示警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!