# Ember CLI Build Using Dynamic Parameter From Config or DotENV

**URL:** <https://discuss.emberjs.com/t/ember-cli-build-using-dynamic-parameter-from-config-or-dotenv/17522>\
**Category:** Ember CLI\
**Created:** [February 16, 2020, 6:35am UTC](https://discuss.emberjs.com/t/ember-cli-build-using-dynamic-parameter-from-config-or-dotenv/17522 "2020-02-16T06:35:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![reykario](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/reykario/32/16915_2.png) [@reykario](https://discuss.emberjs.com/u/reykario)\
**Post date:** [February 16, 2020, 6:35am UTC](https://discuss.emberjs.com/t/ember-cli-build-using-dynamic-parameter-from-config-or-dotenv/17522/1 "2020-02-16T06:35:59Z")

</div>

Hello i have a question regarding the ember-cli-build.

So i have ember apps that intended to load different assets (css,js,addons) based on parameter that i add in [dotEnv](https://github.com/fivetanley/ember-cli-dotenv) or in config/environment.js. The aim is to make ember app able to load dynamic asset based from where the url is accesssed.

The Questions is. Does ember-cli-build can get configuration parameter or get another value from dotEnv file ?

---

<div class="post-metadata">

**Author:** ![dknutsen](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/dknutsen/32/16471_2.png) [@dknutsen](https://discuss.emberjs.com/u/dknutsen)\
**Post date:** [February 18, 2020, 7:12pm UTC](https://discuss.emberjs.com/t/ember-cli-build-using-dynamic-parameter-from-config-or-dotenv/17522/2 "2020-02-18T19:12:16Z")

</div>

The `ember-cli-build.js` file is just a node script at the end of the day so you can use environment variables via `process.env.<varname>` or you could use something like dotenv (you’d just have to install globally or locally and import it). Hope that answers your question!

---

<div class="post-metadata">

**Author:** ![Garrick](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/garrick/32/12156_2.png) [@Garrick](https://discuss.emberjs.com/u/Garrick)\
**Post date:** [February 20, 2020, 2:50am UTC](https://discuss.emberjs.com/t/ember-cli-build-using-dynamic-parameter-from-config-or-dotenv/17522/3 "2020-02-20T02:50:44Z")

</div>

I’d like to add that you can also access `process.env` in `config/environment.js` so that you set properties at build time and access then at run time.

---

<div class="post-metadata">

**Author:** ![jelhan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jelhan/32/16917_2.png) [@jelhan](https://discuss.emberjs.com/u/jelhan)\
**Post date:** [February 20, 2020, 1:22pm UTC](https://discuss.emberjs.com/t/ember-cli-build-using-dynamic-parameter-from-config-or-dotenv/17522/4 "2020-02-20T13:22:04Z")

</div>

> [@reykario](#):
>
> The aim is to make ember app able to load dynamic asset based from where the url is accesssed.

I’m not sure if dynamic variables at build-time will help you with that goal. The build is done once. The output is a bundle of static HTML, CSS, JavaScript and maybe some additional files like images. Generating a build per request is not a good idea for performance reasons.

If it’s a fixed list of values, you may generate builds for all possible values once and then serve them depending on request origin.

If it’s not a fixed list, I would recommend to do one build and alter the run-time configuration when serving the file. The run-time configuration is included in `index.html` as a `<meta>` tag. It’s a URI encoded JSON.

---

<div class="post-metadata">

**Author:** ![reykario](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/reykario/32/16915_2.png) [@reykario](https://discuss.emberjs.com/u/reykario)\
**Post date:** [February 21, 2020, 5:33am UTC](https://discuss.emberjs.com/t/ember-cli-build-using-dynamic-parameter-from-config-or-dotenv/17522/5 "2020-02-21T05:33:48Z")

</div>

Hello thanks for the response. Yes i figured generating build per request is not possible. However including all fixed list would load unnecesarry assets and affect the loadtime.

So in the end i use [Ember Cli Head](https://github.com/ronco/ember-cli-head) to able load dynamic assets in and use jquery to append the js file. Although i am not sure that was the cleanest way to do external js loading.

---

<div class="post-metadata">

**Author:** ![jelhan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jelhan/32/16917_2.png) [@jelhan](https://discuss.emberjs.com/u/jelhan)\
**Post date:** [February 21, 2020, 11:24am UTC](https://discuss.emberjs.com/t/ember-cli-build-using-dynamic-parameter-from-config-or-dotenv/17522/6 "2020-02-21T11:24:30Z")

</div>

> [@reykario](#):
>
> However including all fixed list would load unnecesarry assets and affect the loadtime.

I did not meant that you should include all assets in one build. I tried to suggest that you could do multiple builds one for each origin. Something like:

```auto
BUILD_FOR_ORIGIN=foo.com ember build --prod --output-path=dist/foo.com 
BUILD_FOR_ORIGIN=bar.com ember build --prod --output-path=dist/bar.com
ember build --prod --output-path=dist/default

```

Upload all builds to your webserver and configure it to serve the correct build depending on request.

This does only work if you know the list of build variants beforehand. And it has a huge impact on time needed to do a full deployment. But it’s far easier and does not have as much edge cases as manipulating the build output.

> [@reykario](#):
>
> So in the end i use [Ember Cli Head](https://github.com/ronco/ember-cli-head) to able load dynamic assets in and use jquery to append the js file. Although i am not sure that was the cleanest way to do external js loading.

That approach has an impact on timing. The dynamic assets won’t be loaded until full application is booted. That might be okay for your use case but could cause issues. I just wanted to mention it for other people coming across this thread.
