问题
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