From c8ec25ecf72dc0a2a1b3d1d814391da6a87cb8c0 Mon Sep 17 00:00:00 2001 From: Andrew Hyndman Date: Wed, 3 Feb 2021 10:16:09 -0800 Subject: [PATCH] Add support for new BUILD_PATH advanced configuration variable (#8986) --- docusaurus/docs/advanced-configuration.md | 1 + packages/react-scripts/config/paths.js | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docusaurus/docs/advanced-configuration.md b/docusaurus/docs/advanced-configuration.md index 7f0189c6fc2..a3000988b62 100644 --- a/docusaurus/docs/advanced-configuration.md +++ b/docusaurus/docs/advanced-configuration.md @@ -18,6 +18,7 @@ You can adjust various development and production settings by setting environmen | WDS_SOCKET_PATH | βœ… Used | 🚫 Ignored | When set, Create React App will run the development server with a custom websocket path for hot module reloading. Normally, `webpack-dev-server` defaults to `/sockjs-node` for the SockJS pathname. You may use this variable to start local development on more than one Create React App project at a time. See [webpack-dev-server documentation](https://webpack.js.org/configuration/dev-server/#devserversockpath) for more details. | | WDS_SOCKET_PORT | βœ… Used | 🚫 Ignored | When set, Create React App will run the development server with a custom websocket port for hot module reloading. Normally, `webpack-dev-server` defaults to `window.location.port` for the SockJS port. You may use this variable to start local development on more than one Create React App project at a time. See [webpack-dev-server documentation](https://webpack.js.org/configuration/dev-server/#devserversockport) for more details. | | PUBLIC_URL | βœ… Used | βœ… Used | Create React App assumes your application is hosted at the serving web server's root or a subpath as specified in [`package.json` (`homepage`)](deployment#building-for-relative-paths). Normally, Create React App ignores the hostname. You may use this variable to force assets to be referenced verbatim to the url you provide (hostname included). This may be particularly useful when using a CDN to host your application. | +| BUILD_PATH | 🚫 Ignored | βœ… Used | By default, Create React App will output compiled assets to a `/build` directory adjacent to your `/src`. You may use this variable to specify a new path for Create React App to output assets. BUILD_PATH should be specified as a path relative to the root of your project. | | CI | βœ… Used | βœ… Used | When set to `true`, Create React App treats warnings as failures in the build. It also makes the test runner non-watching. Most CIs set this flag by default. | | REACT_EDITOR | βœ… Used | 🚫 Ignored | When an app crashes in development, you will see an error overlay with clickable stack trace. When you click on it, Create React App will try to determine the editor you are using based on currently running processes, and open the relevant source file. You can [send a pull request to detect your editor of choice](https://github.com/facebook/create-react-app/issues/2636). Setting this environment variable overrides the automatic detection. If you do it, make sure your systems [PATH]() environment variable points to your editor’s bin folder. You can also set it to `none` to disable it completely. | | CHOKIDAR_USEPOLLING | βœ… Used | 🚫 Ignored | When set to `true`, the watcher runs in polling mode, as necessary inside a VM. Use this option if `npm start` isn't detecting changes. | diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index 516513081b2..67ba927fc80 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -29,6 +29,8 @@ const publicUrlOrPath = getPublicUrlOrPath( process.env.PUBLIC_URL ); +const buildPath = process.env.BUILD_PATH || 'build'; + const moduleFileExtensions = [ 'web.mjs', 'mjs', @@ -60,7 +62,7 @@ const resolveModule = (resolveFn, filePath) => { module.exports = { dotenv: resolveApp('.env'), appPath: resolveApp('.'), - appBuild: resolveApp('build'), + appBuild: resolveApp(buildPath), appPublic: resolveApp('public'), appHtml: resolveApp('public/index.html'), appIndexJs: resolveModule(resolveApp, 'src/index'), @@ -83,7 +85,7 @@ const resolveOwn = relativePath => path.resolve(__dirname, '..', relativePath); module.exports = { dotenv: resolveApp('.env'), appPath: resolveApp('.'), - appBuild: resolveApp('build'), + appBuild: resolveApp(buildPath), appPublic: resolveApp('public'), appHtml: resolveApp('public/index.html'), appIndexJs: resolveModule(resolveApp, 'src/index'), @@ -119,7 +121,7 @@ if ( module.exports = { dotenv: resolveOwn(`${templatePath}/.env`), appPath: resolveApp('.'), - appBuild: resolveOwn('../../build'), + appBuild: resolveOwn(path.join('../..', buildPath)), appPublic: resolveOwn(`${templatePath}/public`), appHtml: resolveOwn(`${templatePath}/public/index.html`), appIndexJs: resolveModule(resolveOwn, `${templatePath}/src/index`),