When running yarn start or npm start to start the project created by create-react-app, the terminal will be cleared. When we are debugging, we often need to output some information in webpack. But it is cleared after start.
Solution:
find node_modules/react-dev-utils/clearConsole.js
the file
'use strict';
function clearConsole() {
if (process.env.REACT_APP_NO_CLEAR_CONSOLE) {
return;
}
process.stdout.write(
process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H'
);
}
module.exports = clearConsole;
After modifying the package.json
file REACT_APP_NO_CLEAR_CONSOLE add variables to the script command
"scripts": {
"start": "REACT_APP_NO_CLEAR_CONSOLE=true node scripts/start.js",
},
It will not be cleared when you use yarn start again.