Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to have `react-scripts` include extra files in the root of the build?

My Situation:

I'm hosting an app created with create-react-app on Surge. In order to have Surge let react-router handle the routes, I have to add a 200.html to the root, and in order to handle 404s, I have to add a 404.html to the root. The problem is, with npm run build, only index.html and favicon.ico are added to the root of the build directory.

Possible Solution:

I can copy other files by making the build script in package.json react-scripts build && cp 200.html 404.html build.

Question:

Is there a better way to have react-scripts add extra files to the root of the build, rather than relying on bash scripting in package.json?

like image 998
Jo Sprague Avatar asked Sep 22 '16 12:09

Jo Sprague


1 Answers

The answer I settled on was to use bash scripts in my package.json as I originally suspected, but I decided to do the file operations in a deploy script instead of the build script, and rename index.html to 200.html instead of copying extra files, as suggested by the create-react-app docs;

"build": "react-scripts build",
"deploy": "npm run build && mv build/index.html build/200.html && surge build mydomain.com"

I think doing the file operation in the deploy script, instead of the build script, is the right solution because that change is unique to the deployment environment, meaning, if I was deploying somewhere other than surge, I might not want to rename the index file.

Still open to other solutions if anyone has a better suggestion.

like image 133
Jo Sprague Avatar answered Oct 14 '22 13:10

Jo Sprague