Description
As 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?