We do something like this and it seems to work ok though I haven’t actually checked really recently:
In ember-cli-build.js:
// get environment
var env = EmberApp.env();
// if we are building for a production environment turn minification on
if(env.indexOf('prod') > -1) {
app.options.minifyCSS.enabled = true;
app.options.minifyJS.enabled = true;
}
How are you verifying that minification is not enabled?
I tried your config in an (almost) brand new app that I’ve been playing with, same version of Ember CLI (2.9.1) and minification seems to work fine. I verified this by running a build (in my case i did it with ember serve -e other) and then opening <project-root>/dist/vendor.js and <project-root>/dist/<appname>.js and they are minified as expected. If i remove that config they are not minified.
You’ll probably notice that the app source is still explorable in the ‘source’ tab of the Chrome (or other browser) dev tools. To disable that I think you’ll want to turn sourcemaps off:
Very simple: when everything is minified, I get an output like this.
$ ember build --environment=production
bootstrap-sassy config: all JS enabled, glyphicons enabled
cleaning up...
Built project successfully. Stored in "dist/".
File sizes:
- demo-1208aea6cf3c124868f73fbf78cd7b93.js: 613 B (334 B gzipped)
- demo-b4aa5e9138764f35037f1d3490616bf9.css: 1.47 KB (663 B gzipped)
- style-045a666e4a8dd115ef4b919501a15212.css: 26.73 KB (6.1 KB gzipped)
...
and css/js files in dist/ are minified.
Otherwise
$ ember build --environment=staging
bootstrap-sassy config: all JS enabled, glyphicons enabled
cleaning up...
Built project successfully. Stored in "dist/".
This is really irritating. Did you find a workaround for this? My use case is this: I need to be able to deploy something that’s production-ready (minified, same exact environment as the actual production site), but point to different staging API hosts. Originally I used the environment variable for that, but I lose minification and other optimizations (I also miss the action behavior that comes with a production environment).
It seems like the way forward is to use other environment variables for that: API_ENVIRONMENT=staging ember build --environment=production, or something similar
Yeah environment variables are recommended. Easiest way to manage this is probably to use ember-cli-deploy which lets you define deploy targets and you can specify which ember build environment you use per target.
The problem is that ember-cli (by design) only supports the basic build environments: testing, development, production. Others will “work” but they’ll basically just default to your ember-cli default build type.
An underlying confusion here is that --environment=production doesn’t mean “build it for my production server” it means “build it for any server”. If you have a production server and a staging server, those are both still --environment=production builds, and the differences between them can be managed easiest using different deploy targets under ember-cli-deploy.
--environment only has three possible settings: development (“I will run it locally”), test (“I will run the test suite”), and production (“I will run it on a server”). You can’t make up extra settings like “staging”.
It’s unfortunate that this flag is named “environment” when something like “mode” might make it clearer how it works.