How can I make `react-scripts build` quiet?

自作多情 提交于 2020-08-27 08:59:12

问题


I am working with a repo with a number of Node packages created with create-react-app, all of which are built and tested by the CI system. Each package's build/test, done with react-scripts build followed by react-scripts test --silent, is currently producing over twenty lines of output resulting in a build log with well over a hundred lines of material such as "File sizes after gzip" and "Find out more about deployment here." This makes it more difficult to see error messages, warnings or other problems in that log.

Is there some way for me to quiet this down short of writing my own custom build script (and possibly test script, too) for each one of the packages? If I do need custom scripts, what's the best way to re-use as much as possible of the existing code that's doing the build and test?


回答1:


react-scripts build runs bin/react-scripts.js from the react-scripts package which basically just runs scripts/build.js from that same package.

Sadly, that build.js script (as of 2018-10-15, anyway) is hard-coded to call functions such as printFileSizesAfterBuild() and printHostingInstructions(), without any option to disable these. So there's currently no way to change this except to make a copy of build.js, modify it not to print the things you don't want, and use that instead.

There is a pull request PR #5429 from @LukasGjetting to add a --silent option to the build script. It's been closed due to lack of inactivity, and the create-react-app developers have made it fairly clear in other places that they're not intending to make react-scripts very configurable; the solution they suggest is just to use your own build.js script.




回答2:


I spontaenously have chalk in mind. At least you can color code the responses. Sounds like the app you are working with is not (yet) ejected. Only when the app is ejected can you modify create-react-app base files. Unfortunately, once ejected you can not reverse the effects. Lmk if it helps



来源:https://stackoverflow.com/questions/52114824/how-can-i-make-react-scripts-build-quiet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!