Last active
December 24, 2021 19:21
-
-
Save brettinternet/af63f58dfba1d24ab760c427a7cae2d0 to your computer and use it in GitHub Desktop.
Cross-platform method to pipe Create React App stdout in order to prevent scripts from clearing the console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"scripts": { | |
"start": "ts-node scripts/start-cra" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { spawn } from 'child_process' | |
import { resolve } from 'path' | |
const cwd = resolve(__dirname) | |
/** | |
* Because CRA refuses to allow users from preventing console clearing | |
* https://github.com/facebook/create-react-app/issues/2495 | |
* | |
* This is the cross-platform equivalent to piping to `cat` | |
* | |
* This is particularly useful when running CRA alongside other runtime processes | |
*/ | |
const start = spawn('npx', ['react-scripts', 'start'], { | |
shell: true, | |
cwd, | |
}) | |
start.stdout.pipe(process.stdout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
facebook/create-react-app#2495