create-react-app 是非常好用的前端 react 脚手架工具,而且还是 Facebook 官方出品的,如果没有特殊的要求,现阶段一般都推荐直接使用这个来构建项目。
但是最近碰到一个问题,折腾了我好久才找到解决方案。
首先我们知道,create-react-app 默认是配置了 eslint 的,但是如果我们不将配置 eject 出来的情况下,我们是无法通过在项目根目录添加 .eslintrc 来配置自定义规则的。
这个规定,之前并不知悉,让我折腾了好一番,才终于接受这个残忍的现实。
而后,我也在官方文档找到了说明:
Note that even if you customise your ESLint config, these changes will only affect the editor integration. They won’t affect the terminal and in-browser lint output. This is because Create React App intentionally provides a minimal set of rules that find common mistakes.
可以看到的是,我们即使配置了 .eslintrc 规则,也只会影响到我们浏览器对于 eslint 规则的运用,无法在编译调试的过程中,对代码进行规范。
说白了,就是,我们必须要用默认的配置。
但