Skip to content

Instantly share code, notes, and snippets.

@KRostyslav
Last active July 8, 2022 19:56
Show Gist options
  • Save KRostyslav/9f8478b93688258a706254777fc63a55 to your computer and use it in GitHub Desktop.
Save KRostyslav/9f8478b93688258a706254777fc63a55 to your computer and use it in GitHub Desktop.
Environments in React App

Environments in React App

// src/config.js

export default {
  s3: {
    BUCKET: "YOUR_S3_BUCKET_NAME",
  },
  api: {
    URL: "YOUR_API_URL",
  },
};

export dev {
  s3: {
    BUCKET: "YOUR_S3_BUCKET_NAME",
  },
  api: {
    URL: "YOUR_API_URL",
  },
};

export prod {
  s3: {
    BUCKET: "YOUR_S3_BUCKET_NAME",
  },
  api: {
    URL: "YOUR_API_URL",
  },
};

const config = process.env.REACT_APP_STAGE === "production" ? prod : dev;

export default {
  // Add common config values here
  MAX_ATTACHMENT_SIZE: 5000000,
  ...config,
};
// package.json

"scripts": {
  "start": "REACT_APP_STAGE=dev react-scripts start",
  "build:dev": "REACT_APP_STAGE=dev react-scripts build",
  "build:prod": "REACT_APP_STAGE=production npm run build",
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment