5

I'd like to create a build of an Ember CLI app for a staging environment. For staging, I'd like to essentially do exactly the same thing as production (minification, fingerprinting, exclude tests, etc), but want to pick up the environment variables for development. To attempt this, I changed my environment.js file to account for staging:

if (environment === 'development' || environment === 'staging') {
  ENV.someApiKey = 'test-api-key';
}

if (environment === 'production') {
  ENV.someApiKey = 'production-api-key';
}

When I run ember build --environment=staging, the proper staging environment variables are set, but all of the other build processes that would run for production doesn't. Is there a way to tell Ember CLI to build for production but pick up environment variables for development?

Johnny Oshika
  • 54,741
  • 40
  • 181
  • 275

1 Answers1

1

Ember sets a flag depending on whether production ONLY is specified in /ember-cli/lib/broccoli/ember-app.js:

var isProduction = this.env === 'production';

and then it uses the settings specific to production.

So if you want to have a staging build use a process to modify the environment.js before your run ember build then when the build is finished revert the file back to normal. We should probably make this process more flexible in the future.

Nikos
  • 7,295
  • 7
  • 52
  • 88
  • Just for clarification, you mean have a script that goes into environment.js and replace all instances of 'development' to 'production' and all instances of 'production' to something random like 'foo'. Then run the build with environment=production then have the script revert everything back? I agree that it would be nice if this was built in to Ember CLI, but your solution seems like a good workaround. – Johnny Oshika May 21 '15 at 19:04
  • You would have a script that changes some variables for the production build, you don't change anything else, eg you would change ENV.APP.LOG_TRANSITIONS = true; – Nikos May 22 '15 at 10:26