Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

🐛 Fix environemnt specific build configuration #37

Merged
merged 3 commits into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/cra-template/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@
},
"scripts": {
"start": "yarn localize && react-scripts start",
"build": "yarn build:dev",
"build:development": "react-scripts build --target=development",
"build:stage": "react-scripts build --target=stage",
"build:master": "react-scripts build --target=production",
"build": "yarn build:development",
"build:development": "export REACT_APP_BUILD_ENV=development && react-scripts build --target=production",
"build:stage": "export REACT_APP_BUILD_ENV=stage && react-scripts build --target=production",
"build:production": "export REACT_APP_BUILD_ENV=production && react-scripts build --target=production",
"build:master": "yarn build:production",
"test:watch": "react-scripts test",
"cypress:open": "cypress open",
"eject": "react-scripts eject",
Expand Down
6 changes: 2 additions & 4 deletions packages/cra-template/template/src/config/config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { merge } from 'lodash';
import { isEnvDevelopment } from 'constants/index';

const { BUILD_ENV, REACT_APP_NAME } = process.env;
// eslint-disable-next-line
const envConfig = require(`./config.${BUILD_ENV}.js`).default;
const envConfig = require(`./config.${process.env.REACT_APP_BUILD_ENV || process.env.NODE_ENV}.js`).default;

const defaults = {
// default configuration goes here
appName: REACT_APP_NAME,
appName: process.env.REACT_APP_NAME,
devTools: isEnvDevelopment,
sentry: {
// TODO: add PUBLIC 'dsn' of your project here:
Expand Down
15 changes: 13 additions & 2 deletions packages/cra-template/template/src/constants/env.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
export const isEnvDevelopment = process.env.NODE_ENV === 'development';
export const isEnvProduction = process.env.NODE_ENV === 'production';
const environments = {
PRODUCTION: 'production',
STAGE: 'stage',
DEVELOPMENT: 'development',
};

export const currentEnv = process.env.REACT_APP_BUILD_ENV || process.env.NODE_ENV;

export const isEnvDevelopment = currentEnv === environments.DEVELOPMENT;
export const isEnvStage = currentEnv === environments.STAGE;
export const isEnvProduction = currentEnv === environments.PRODUCTION;

export const isServerEnv = typeof window === 'undefined';

export default environments;
1 change: 1 addition & 0 deletions packages/cra-template/template/src/constants/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as env } from './env';
export * from './env';