The First Part: Background
There are two different environments with two country, some features are different while others are similar. They are in one project, so we need some changes to control whether those features show.
The Second Part: The first try
- split one
env.devfile into two file, one is still.env.devand the other is.env.devus,
.env.dev
...
REGION=eu
.env.devus
- ``
...
REGION=us
- common hook
import envs from "aws-envs";
export const useRegion = () => {
const region = envs.REGION;
const isRegionUS = region === "us";
return {
region,
isRegionUS,
};
};
- when the feature is only in the us environment, the code will look like this:
const App = () => {
const { isRegionUS } = useRegion();
return <>{
isRegionUS && <>US<>
}</>
}
The Third Part: Split a project into two projects with common modules
- directory
...
apps
|__ rentancy-uk // UK environment
|__ ...
|__ src
|__ package.json
|__ rentancy-us // US environment
|__ ...
|__ src
|__ package.json // override path: "@rentancy/*": [ "../../../packages/*/src"]
packages
|__ common
|__src // common features
|__ ui // UI component
.env.dev
.env.devus
package.json
- when we want to use modules in packages/ui, import them like the following code
import { UploadArea } from "@rentancy/ui";
- build
"scripts": { "build": "lerna run build --scope @rentancy/ui" }
Reference: