# Use prod environment file with Ionic 5 React

**URL:** <https://forum.ionicframework.com/t/use-prod-environment-file-with-ionic-5-react/190054>\
**Category:** Ionic React\
**Created:** [May 25, 2020, 10:27am UTC](https://forum.ionicframework.com/t/use-prod-environment-file-with-ionic-5-react/190054 "2020-05-25T10:27:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dadu](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@dadu](https://forum.ionicframework.com/u/dadu)\
**Post date:** [May 25, 2020, 10:27am UTC](https://forum.ionicframework.com/t/use-prod-environment-file-with-ionic-5-react/190054/1 "2020-05-25T10:27:34Z")

</div>

For angular projects, you can create an environment.ts file and environment.prod.ts file to manage different values for dev and prod builds so that when building with --prod option, the environment.prod.ts file is used when importing environment.

This is not working for ionic 5 with react? Is there a way to achieve this with an Ionic 5 React project?

---

<div class="post-metadata">

**Author:** ![mirkonasato](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mirkonasato/32/131398_2.png) [@mirkonasato](https://forum.ionicframework.com/u/mirkonasato)\
**Post date:** [May 25, 2020, 12:02pm UTC](https://forum.ionicframework.com/t/use-prod-environment-file-with-ionic-5-react/190054/2 "2020-05-25T12:02:29Z")

</div>

You can use [Environment Variables](https://create-react-app.dev/docs/adding-custom-environment-variables/), as documented in the Create React App docs.

---

<div class="post-metadata">

**Author:** ![dadu](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@dadu](https://forum.ionicframework.com/u/dadu)\
**Post date:** [May 25, 2020, 6:03pm UTC](https://forum.ionicframework.com/t/use-prod-environment-file-with-ionic-5-react/190054/3 "2020-05-25T18:03:33Z")

</div>

Thanks. This seems to work although every ionic build is production when checking the NODE\_ENV variable, so can’t use the --prod flag to create a specific prod build

---

<div class="post-metadata">

**Author:** ![mirkonasato](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mirkonasato/32/131398_2.png) [@mirkonasato](https://forum.ionicframework.com/u/mirkonasato)\
**Post date:** [May 26, 2020, 9:04am UTC](https://forum.ionicframework.com/t/use-prod-environment-file-with-ionic-5-react/190054/4 "2020-05-26T09:04:35Z")

</div>

Yes for React projects the Ionic CLI calls [react-scripts](https://github.com/facebook/create-react-app/tree/master/packages/react-scripts#react-scripts), and `react-scripts build` always creates a production build. ([Here’s why](https://github.com/facebook/create-react-app/issues/2880#issuecomment-319120228).)

---

<div class="post-metadata">

**Author:** ![dadu](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@dadu](https://forum.ionicframework.com/u/dadu)\
**Post date:** [May 26, 2020, 10:24am UTC](https://forum.ionicframework.com/t/use-prod-environment-file-with-ionic-5-react/190054/5 "2020-05-26T10:24:32Z")

</div>

Thanks, I’m new to react, but I see why this happens now.

There are workarounds posted on the react forum and documented [here](https://create-react-app.dev/docs/deployment/#customizing-environment-variables-for-arbitrary-build-environments). Unfortunately as ionic build always calls `react-scripts build` as you rightly said, this does not work for ionic.

---

<div class="post-metadata">

**Author:** ![mirkonasato](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mirkonasato/32/131398_2.png) [@mirkonasato](https://forum.ionicframework.com/u/mirkonasato)\
**Post date:** [May 26, 2020, 10:39am UTC](https://forum.ionicframework.com/t/use-prod-environment-file-with-ionic-5-react/190054/6 "2020-05-26T10:39:21Z")

</div>

> [@dadu](#):
>
> Unfortunately as ionic build always calls `react-scripts build` as you rightly said, this does not work for ionic.

Nothing is stopping you from using `react-scripts` directly if you want to.

---

<div class="post-metadata">

**Author:** ![HardikSA](https://avatars.discourse-cdn.com/v4/letter/h/ecccb3/32.png) [@HardikSA](https://forum.ionicframework.com/u/HardikSA)\
**Post date:** [April 18, 2021, 6:45am UTC](https://forum.ionicframework.com/t/use-prod-environment-file-with-ionic-5-react/190054/7 "2021-04-18T06:45:30Z")

</div>

As ionic-react always build with production config, How can we have 2 env files for the production environment? For example on for the beta channel and one for real production

Like I would like to have one env for developement and one for the production, but When I create android build it will always take the production one
