Use custom build output folder when using create-react-app

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.

Answers 1

  • 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:

    1. 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.

    2. You could try to eject create-react-app and tweak the configuration.

      If you aren’t satisfied with the build tool and configuration choices, you can eject at any time. This command will remove the single build dependency from your project.

      Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except eject will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

      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!

Related Articles