From 0a6e14ac90e639a9cef9e1400078ba1898e06fc4 Mon Sep 17 00:00:00 2001 From: d3jan Date: Wed, 8 Dec 2021 18:43:16 +0100 Subject: [PATCH 1/2] Add support for new ENTRY_PATH advanced configuration variable --- docusaurus/docs/advanced-configuration.md | 1 + packages/react-scripts/config/paths.js | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docusaurus/docs/advanced-configuration.md b/docusaurus/docs/advanced-configuration.md index 34144ce6040..de34d594a0a 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 `/ws` 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. | +| ENTRY_PATH | βœ… Used | βœ… Used | By default, Create React App will use `src/index` as an entry point. You may use this variable to specify a new entry point for Create React App. ENTRY_PATH should be specified as a path relative to the root of your project. | | 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. | diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index f4470a02f63..5cd31ebf975 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -30,6 +30,7 @@ const publicUrlOrPath = getPublicUrlOrPath( ); const buildPath = process.env.BUILD_PATH || 'build'; +const entryPath = process.env.ENTRY_PATH || 'src/index' const moduleFileExtensions = [ 'web.mjs', @@ -65,7 +66,7 @@ module.exports = { appBuild: resolveApp(buildPath), appPublic: resolveApp('public'), appHtml: resolveApp('public/index.html'), - appIndexJs: resolveModule(resolveApp, 'src/index'), + appIndexJs: resolveModule(resolveApp, entryPath), appPackageJson: resolveApp('package.json'), appSrc: resolveApp('src'), appTsConfig: resolveApp('tsconfig.json'), @@ -90,7 +91,7 @@ module.exports = { appBuild: resolveApp(buildPath), appPublic: resolveApp('public'), appHtml: resolveApp('public/index.html'), - appIndexJs: resolveModule(resolveApp, 'src/index'), + appIndexJs: resolveModule(resolveApp, entryPath), appPackageJson: resolveApp('package.json'), appSrc: resolveApp('src'), appTsConfig: resolveApp('tsconfig.json'), @@ -128,7 +129,7 @@ if ( appBuild: resolveOwn(path.join('../..', buildPath)), appPublic: resolveOwn(`${templatePath}/public`), appHtml: resolveOwn(`${templatePath}/public/index.html`), - appIndexJs: resolveModule(resolveOwn, `${templatePath}/src/index`), + appIndexJs: resolveModule(resolveOwn, path.join(templatePath, entryPath)), appPackageJson: resolveOwn('package.json'), appSrc: resolveOwn(`${templatePath}/src`), appTsConfig: resolveOwn(`${templatePath}/tsconfig.json`), From 676526cdc9af54ee9d512f7e588809a12cf1d66f Mon Sep 17 00:00:00 2001 From: d3jan Date: Thu, 9 Dec 2021 15:15:46 +0100 Subject: [PATCH 2/2] Add support for PUBLIC_PATH env variable --- docusaurus/docs/advanced-configuration.md | 1 + packages/react-scripts/config/paths.js | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docusaurus/docs/advanced-configuration.md b/docusaurus/docs/advanced-configuration.md index de34d594a0a..4669715f73e 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 `/ws` 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. | +| PUBLIC_PATH | βœ… Used | βœ… Used | By default, Create React App will use `public` as an entry point. You may use this variable to specify a new public for Create React App. PUBLIC_PATH should be specified as a path relative to the root of your project. | | ENTRY_PATH | βœ… Used | βœ… Used | By default, Create React App will use `src/index` as an entry point. You may use this variable to specify a new entry point for Create React App. ENTRY_PATH should be specified as a path relative to the root of your project. | | 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. | diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index 5cd31ebf975..2727ef6806d 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -29,8 +29,9 @@ const publicUrlOrPath = getPublicUrlOrPath( process.env.PUBLIC_URL ); +const publicPath = process.env.PUBLIC_PATH || 'public'; +const entryPath = process.env.ENTRY_PATH || 'src/index'; const buildPath = process.env.BUILD_PATH || 'build'; -const entryPath = process.env.ENTRY_PATH || 'src/index' const moduleFileExtensions = [ 'web.mjs', @@ -64,8 +65,8 @@ module.exports = { dotenv: resolveApp('.env'), appPath: resolveApp('.'), appBuild: resolveApp(buildPath), - appPublic: resolveApp('public'), - appHtml: resolveApp('public/index.html'), + appPublic: resolveApp(publicPath), + appHtml: resolveApp(path.join(publicPath, 'index.html')), appIndexJs: resolveModule(resolveApp, entryPath), appPackageJson: resolveApp('package.json'), appSrc: resolveApp('src'), @@ -89,8 +90,8 @@ module.exports = { dotenv: resolveApp('.env'), appPath: resolveApp('.'), appBuild: resolveApp(buildPath), - appPublic: resolveApp('public'), - appHtml: resolveApp('public/index.html'), + appPublic: resolveApp(publicPath), + appHtml: resolveApp(path.join(publicPath, 'index.html')), appIndexJs: resolveModule(resolveApp, entryPath), appPackageJson: resolveApp('package.json'), appSrc: resolveApp('src'), @@ -127,8 +128,8 @@ if ( dotenv: resolveOwn(`${templatePath}/.env`), appPath: resolveApp('.'), appBuild: resolveOwn(path.join('../..', buildPath)), - appPublic: resolveOwn(`${templatePath}/public`), - appHtml: resolveOwn(`${templatePath}/public/index.html`), + appPublic: resolveOwn(path.join(templatePath, publicPath)), + appHtml: resolveOwn(path.join(templatePath, publicPath, 'index.html')), appIndexJs: resolveModule(resolveOwn, path.join(templatePath, entryPath)), appPackageJson: resolveOwn('package.json'), appSrc: resolveOwn(`${templatePath}/src`),