Created by: ajhyndman
Summary
Adds support for a new environment variable, BUILD_PATH
, which overrides the create-react-app output directory.
Fixes #378 Fixes #778 (closed) Fixes #1354 (closed) Fixes #3824 (closed) Fixes #3973 (closed) Fixes #6211 (closed) Relates to #7802 Fixes #8600 (closed)
Rationale
First, I know, this is a hot button issue. I have been following create-react-app for years now, and I understand and support the objective of providing a configuration-free setup experience for new React projects. However, I hope you'll allow me a few paragraphs to make an argument for this change.
I think there are several qualities about build path configuration that make it a good candidate as an addition to create-react-app's set of "advanced configuration" environment variables:
- It's trivial to support. Including documentation, this whole diff is less than 10 lines of code.
- CRA is very hands-off about what you do with build output, so this change is unlikely to add a maintenance burden.
- It still generates issues and support requests.
- There are real compatibility issues that existing recommendations can't resolve.
- The
mv
command is not cross-platform compatible - The 'build' path can conflict with other tooling
- Symlink-based build systems are hard to support
- The
- A large number of users describe or recommend ejecting solely for the purpose of changing output path.
In summary, I think that a customisable output path is: cheap to support, won't add to maintenance burden, reduces ongoing support work, and allows significantly more projects to avoid ejecting and benefit from future CRA updates. Together, I think these qualities make a new BUILD_PATH
environment variable a good candidate for support.
Verification
To verify this change works, I followed the guide in CONTRIBUTING.md and bootstrapped a project locally.
$ cd create-react-app
$ yarn
$ yarn create-react-app my-app
In that project, I verified the following configuration cases:
- With no configuration, files are still output to
/build
:
- With the unprefixed folder name 'dist', files are output to
/dist
:
- With a parent-relative path specified, files are output to the correct location:
In the third case, I also verified running yarn build
multiple times correctly cleans up files before outputting a new build.
Thank you to the create-react-app team being such exemplary members of the React and open source communities, and I appreciate you considering my pull request.