Skip to content

Instantly share code, notes, and snippets.

@brettinternet
Last active December 24, 2021 19:21
Show Gist options
  • Save brettinternet/af63f58dfba1d24ab760c427a7cae2d0 to your computer and use it in GitHub Desktop.
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
{
"scripts": {
"start": "ts-node scripts/start-cra"
}
}
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)
@brettinternet
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment