Proposal: `run` and `watch` scripts to use different entry points
See original GitHub issueAs I start to build out real apps I find cases where I want to run a one-off script using the same language features as the rest of my app. If the only way to enter my code is via npm start
then there’s no way to do this.
The proposed solution is to add two more scripts, react-scripts run
and react-scripts watch
that the developer can use to make their own npm script which uses the same babel environment. For example, let’s say you had a script src/populate.js
to populate initial data in a remote backend. You could add to your npm scripts:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"eject": "react-scripts eject",
"populate": "react-scripts run src/populate.js"
},
and then when you ran npm run populate
it would invoke src/populate.js
but do all the babel preprocessing to let you use ES6 features. watch
would work just like run
, but when any file changed it would restart the process. So watch
would be used for long-running processes; run
would be used for one-off scripts. run
here works similarly to rails run
if you are familiar with rails.
Without this sort of feature, developers are likely to make these one-off scripts using ES5 or using whatever language subset is node-compatible. This would also be a useful hook for people who wanted to build node server functionality, while not forcing it on anyone.
What do you think?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:15 (10 by maintainers)
Top GitHub Comments
We’re using a mono-repo and link local dependencies within the same repo for fast development. It’s sometimes helpful to run watch on dependent module and develop on it while running it as a dependency. I think this would be a nice feature to have.
OK I am going to take a stab at creating
run
, and then depending on how that goes maybewatch
will also be useful.