Facebook provides a create-react-app
command to build react apps. When we run npm run build
, we see output in /build
folder.
npm run build
Builds the app for production to the build folder. It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes. Your app is ready to be deployed!
How can we use custom folder instead of /build
for the output? Thanks.
I had the scenario like want to rename the folder and change the build output location, and used below code in the package.json with the latest version
"build": "react-scripts build && mv build ../my_bundles",
Open Command Prompt inside your Application's source. Run the Command
Open your scripts/build.js file and add this at the beginning of the file after 'use strict' line
Open your config/paths.js and modify the buildApp property in the exports object to your destination folder. (Here, I provide 'react-app-scss' as the destination folder)
Run
Note: Running Platform dependent scripts are not advisable
Félix's answer is correct and upvoted, backed-up by Dan Abramov himself.
But for those who would like to change the structure of the output itself (within the
build
folder), one can run post-build commands with the help ofpostbuild
, which automatically runs after thebuild
script defined in thepackage.json
file.The example below changes it from
static/
touser/static/
, moving files and updating file references on relevant files (full gist here):package.json
postbuild.sh
Create-react-app Version 2+ answer
For recent (> v2) versions of create-react-app (and possible older as well), add the following line to your package.json, then rebuild.
You should now see the build/index.html will have relative links
./static/...
instead of links to the server root:/static/...
.