Customizing the build process
You can customize the build process to rename an app, add a new app name, or build an app bundle without a React route basename.
Renaming an app for a build
To rename an app so that the app is bundled into a different name when it is build, you must complete the following updates using the new app name.
- In the tools/scripts/buildConstant.js file replace the constants ALL_APP and DEFAULT_APP with the new app name.
- In the .env file, replace
REACT_APP_STORENAME with the new app name. This
variable is used only if the REACT_APP_STORENAME
variable is not defined in .env.development or
.env.production files.
For more information, see Adding Development Environment Variables In .env for the Create React App.
- In the assets folder, rename or copy the
emerald or sapphire folder to
the new app name. Replace the static assets in the folder, for example
images, with new app specific assets.Note: To avoid potential conflicts or issues with different operating systems, use a lowercase folder name.
- Replace the CSS theme in the src/themes folder.
- Rename or create the files appa-theme.js and appb-theme.js.
- Find and edit the index.js file to add the
following
commands:
import { emeraldTheme as Emerald, sapphireTheme as Sapphire, } from "@hcl-commerce-store-sdk/react-component"; + import AppA from "./appa-theme"; + import AppB from "./appb-theme"; + const themes = { AppA, AppB }; const CurrentTheme = themes[process.env.REACT_APP_STORENAME]; export { CurrentTheme };
- run
npm run build
ornpm start
.
Adding a new app name
- In the tools/scripts/buildConstant.js file add the new app name to the constants ALL_APP and DEFAULT_APP.
- In the assets folder, add a new sub-folder with the new
app name.Note: To avoid potential conflicts or issues with different operating systems, use a lowercase folder name.
- In the src/themes folder, create the CSS theme files appa-theme.js and appb-theme.js.
- Find and edit the index.js file to add the following
commands:
import { emeraldTheme as Emerald, sapphireTheme as Sapphire, } from "@hcl-commerce-store-sdk/react-component"; - const themes = { Emerald, Sapphire }; + import AppA from "./appa-theme"; + import AppB from "./appb-theme"; + const themes = { AppA, AppB, Emerald, Sapphire }; const CurrentTheme = themes[process.env.REACT_APP_STORENAME]; export { CurrentTheme };
- run
npm run build
ornpm start
.
Enabling a Google API key
- Directions API
- Distance Matrix API
- Maps JavaScript API
- Places API
- Follow the steps in the following links:
- Use the environment variable
REACT_APP_GOOGLE_MAP_API_KEY=
your google API key to add the key to the store .env file. - Build and deploy the store bundle.
Build app bundle without React route basename
basename plays a role similar to context root in React Router world.
In cases where the basename is not applicable, we can remove the basename for app.
To remove the basename, in assets/template folder, remove the REACT_APP_ROUTER_BASENAME entries in .env template files.
PORT={{port}}
HTTPS={{https}}
REACT_APP_STORENAME={{appName}}
- REACT_APP_ROUTER_BASENAME={{appName}}
+ REACT_APP_ROUTER_BASENAME=
basename is a React Router concept. For details related to basename, refer to http://reactrouter.com/web/api/BrowserRouter.
App serving from document root of a web server
REACT_APP_STORENAME={{appName}}
REACT_APP_ROUTER_BASENAME={{appName}}
- PUBLIC_URL=/{{appName}}
Web Server rewrite for Single Page App
Please refer to Create React App Serving Apps with Client-Side Routing for different deployment options and web server configuration.