Create React App does not provide watching build mode oficially (#1070).
This script provides watching build mode for an external tool such as Chrome Extensions or Firebase app.
Create a React app.
Put the script into scripts/watch.js
.
Add watch
task into the scripts block in package.json
as follows:
"scripts": {
"start": "react-scripts start",
// Add next line
"watch": "node scripts/watch.js",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
Run the watch
task.
npm run watch
Change source code and check build
output.
Directory structure may be following:
app/
src/
public/
scripts/
watch.js
(need to add)
package.json
(need to modify)build/
(output)
Looks like this script does not respond to
PUBLIC_URL="./"
env variable. (Very useful when you need to have relative URLs like with VSCode plugins )I know nothing, so I just added
conf.output.publicPath = process.env.PUBLIC_URL
. It worked But why would it not propagate?I'm not sure this is needed - you can always use the
BUILD_PATH
env variable.For example:
cross-env-shell BUILD_PATH=$INIT_CWD/build npm run watch