Eki Eqbal
Eki Eqbal

Reputation: 6037

How to add a custom environment for Ember js?

I'm using Ember.js 2.5.0 and it seems at the moment Ember is limited to the three environments development, test and production. How can I add some other env like as for example staging?

I have a staging server so we can test our app and I want to use different configurations there (than the development one). Any workaround to do that?

Upvotes: 3

Views: 1394

Answers (2)

GUL
GUL

Reputation: 1195

I had the same problem and I've resolved it editing two files environment.js and ember-cli-build.js

In environment.js I've added another IF to set values for the new environment:

if(environment === "stage") {
  ENV.APP.xxxx = 'stage value'
}

In ember-cli-build.js I've customized how the fingerprint is enabled or not. You can do the same for other settings.

module.exports = function(defaults) {
  var fingerprintEnabled = false;
  var env = process.env.EMBER_ENV || 'development';
  switch (env) {
    case 'development':
      fingerprintEnabled = false;
      break;
    case 'test':
      fingerprintEnabled = false;
      break;
    case 'production':
    case 'stage':
      fingerprintEnabled = true;
      break;
  }
  var app = new EmberApp(defaults, {
    fingerprint: {
      enabled: fingerprintEnabled,
      exclude: [...]
    }
    // Add options here
  });

When building the app I pass the proper environment flag:

ember build --environment=stage

Upvotes: 5

TameBadger
TameBadger

Reputation: 1590

As it states in ember-cli documentation, ember-cli is limited to three environments at the moment.

The best workaround at this stage is to use something like ember-cli-dotenv. Have a look specifically at this part of the readme.

Pasted here for easier reference:

// ember-cli-build.js

module.exports = function(defaults) {
  var app = new EmberApp(defaults, {
    dotEnv: {
      clientAllowedKeys: ['DROPBOX_KEY'],
      path: './path/to/.env'
    }
  });

  return app.toTree();
};

Where DROPBOX_KEY can now be anything according do your .env.

Related SO question.

Upvotes: 2

Related Questions