# How build a specific configuration according to target?

**URL:** <https://forum.ionicframework.com/t/how-build-a-specific-configuration-according-to-target/121083>\
**Category:** ionic-v3\
**Created:** [February 10, 2018, 3:21pm UTC](https://forum.ionicframework.com/t/how-build-a-specific-configuration-according-to-target/121083 "2018-02-10T15:21:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![clemdesign](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@clemdesign](https://forum.ionicframework.com/u/clemdesign)\
**Post date:** [February 10, 2018, 3:21pm UTC](https://forum.ionicframework.com/t/how-build-a-specific-configuration-according-to-target/121083/1 "2018-02-10T15:21:49Z")

</div>

Hello,

I would like to know if there is possible with Ionic to build a specific configuration according target…  
i.e. When I use “ionic serve”, backend API of localhost server is used , but when I use “ionic cordova run”, I would like that backend API of my real server is used. If there is a way to do it, I’m very interested…

Idea is to have a snapshot of configuration used by the project, and when is requested, possibility to switch to another snapshot of configuration.  
In C/C++ projects, this functionnality is visible by “Development/Release” environment.

Thank you,  
Clem

---

<div class="post-metadata">

**Author:** ![rlouie](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rlouie/32/134973_2.png) [@rlouie](https://forum.ionicframework.com/u/rlouie)\
**Post date:** [February 10, 2018, 4:06pm UTC](https://forum.ionicframework.com/t/how-build-a-specific-configuration-according-to-target/121083/2 "2018-02-10T16:06:12Z")

</div>

There around definitely ways to achieve this, I wrote a tutorial on this, have a look: [http://roblouie.com/article/296/ionic-2-environment-variables-the-best-way/](http://roblouie.com/article/296/ionic-2-environment-variables-the-best-way/)

---

<div class="post-metadata">

**Author:** ![clemdesign](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@clemdesign](https://forum.ionicframework.com/u/clemdesign)\
**Post date:** [February 10, 2018, 7:43pm UTC](https://forum.ionicframework.com/t/how-build-a-specific-configuration-according-to-target/121083/3 "2018-02-10T19:43:30Z")

</div>

Thank you a lot for your tutorial.

I follow it but in my side, it doesn’t work. It seems that “–prod” is not considered by App, when I start in “ionic serve --prod” environment, the dev is loaded.

Any idea?

Note: I has been to use InjectionToken instead OpaqueToken in my project (I use Ionic 3/Angular 4)

---

<div class="post-metadata">

**Author:** ![rlouie](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rlouie/32/134973_2.png) [@rlouie](https://forum.ionicframework.com/u/rlouie)\
**Post date:** [February 10, 2018, 8:50pm UTC](https://forum.ionicframework.com/t/how-build-a-specific-configuration-according-to-target/121083/4 "2018-02-10T20:50:47Z")

</div>

Yep, you’re right about the token change .

Regarding the --prod flag, evidently you can only use that during the `build` task now, it no longer works during serve.

I suppose this mostly makes sense as you’d really only use prod when going to production, in which case you would build and deploy to a phone.

If you do need to use environment variables while using serve, you can use NODE\_ENV instead. Check the Wrap Up section of my tutorial, and the git project.

Short version is you can just create a task in your package.json that sets NODE\_ENV to whatever value you want:

```auto
"scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve",
    "ionic:serve:qa": "NODE_ENV=qa ionic-app-scripts serve" // THIS IS THE ONE I CREATED
  },

```

Then in your environment variables module just check for `process.env.NODE_ENV` instead of `process.env.IONIC_ENV`.

Since NODE\_ENV is a separate environment variable on your compueter it doesn’t matter what options ionic accepts. So this should definitely work and will also allow you to set more than 2 environments if needed.

---

<div class="post-metadata">

**Author:** ![clemdesign](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@clemdesign](https://forum.ionicframework.com/u/clemdesign)\
**Post date:** [February 11, 2018, 12:19pm UTC](https://forum.ionicframework.com/t/how-build-a-specific-configuration-according-to-target/121083/5 "2018-02-11T12:19:02Z")

</div>

So, I’m tried your git project and it doesn’t work on my side.

But after analyzing, I think to have find the problem: I use Windows system.

I found a solution that works on my side, I shall to set NODE\_ENV environment by the Windows way. So, to load (regarding your project) qa variables, I shall execute the following commands:

```auto
set NODE_ENV=qa
ionic serve

```

I will create a batch file to shortcut commands.

So thank you so much to give me a good way to have a solution 🙂

---

<div class="post-metadata">

**Author:** ![rlouie](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rlouie/32/134973_2.png) [@rlouie](https://forum.ionicframework.com/u/rlouie)\
**Post date:** [February 11, 2018, 4:40pm UTC](https://forum.ionicframework.com/t/how-build-a-specific-configuration-according-to-target/121083/6 "2018-02-11T16:40:55Z")

</div>

No problem, sorry I didn’t mention my config was for is. Keep in mind you can make an npm trash that does that for you, sets the variable and then does serve. That way you just have to run ‘npm run my-task’.

Just shorter to type each time than manually resetting the environment variable

---

<div class="post-metadata">

**Author:** ![clemdesign](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@clemdesign](https://forum.ionicframework.com/u/clemdesign)\
**Post date:** [February 11, 2018, 9:17pm UTC](https://forum.ionicframework.com/t/how-build-a-specific-configuration-according-to-target/121083/7 "2018-02-11T21:17:51Z")

</div>

Thank you for you advise but using batch, I think it is more simple and smaller. For instance, I have created the command `iserve` with only `--prod`, `--dev` or `--fix` as argument in charge to execute `ionic serve --lab` in the good environment.

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:51pm UTC](https://forum.ionicframework.com/t/how-build-a-specific-configuration-according-to-target/121083/8 "2021-07-19T21:51:19Z")

</div>


