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.
webpack =>
renamed as build to dist
Windows Powershell Script
Running
npm run postbuildNamingScript
in powershell will move the JS files to 'build/new-folder-name' and point to the new location from the HTML.You can't change the build output folder name with the current configuration options.
Moreover, you shouldn't. This is a part of the philosophy behind
create-react-app
: they say Convention over Configuration.If you really need to rename your folder, I see two options:
Right after the build process finishes, write a command that copies the build folder content to another folder you want. For example you can try the
copyfiles
npm package, or anything similar.You could try to eject create-react-app and tweak the configuration.
However, it is important to note that this is a one-way operation. Once you eject, you can’t go back! You loose all future updates.
Therefore, I'd recommend you to not use a custom folder naming, if possible. Try to stick with the default naming. If not an option, try #1. If it still doesn't work for your specific use-case and you're really out of options - explore #2. Good luck!
Based on the answers by Ben Carp and Wallace Sidhrée:
This is what I use to copy my entire build folder to my wamp public folder.
package.json
post_build.ps1
The homepage line is only needed if you are deploying to a subfolder on your server (See This answer from another question).
Edit your package.json:
You can update the configuration with a little hack, under your root directory:
replace --your directory of choice-- with the folder directory you want it to build on
note the path I provided can be a bit dirty, but this is all you need to do to modify the configuration.