Production ready build in Ember

I have been building a web app in Ember, and am ready to upload it on a server.

What “ember build --environment production” does?

Need to change any settings in environment.js?

The short answer is “maybe nothing but it really depends”. What settings you might want to change depend on a few things:

  1. your backend (what type of API it is, where it’s located, etc). If your backend serves the app and the API at the same location you might be fine without any changes
  2. what addons you are using (some of the should be configured, sometimes differently in production)
  3. where your front-end app will be deployed, deploying a single page application can sometimes be tricky because you don’t want requests to, say, <app>/foo/bar/1 to actually request <app>/foo/bar/1.html from the server. One of the ways around this is setting locationType in config/environment.js to “hash”, but then your URLs look like <app>/#/foo/bar/1, so many people prefer to configure the server side instead. Really depends.
  4. Any other environmental differences like API keys, etc.

The biggest one you may want to configure is your backend, but depending on what that looks like you may not have to configure much of anything at first. If you can post some more details about your backend, production target (for the ember app, e.g. S3, Apache, etc.), and any third party addons or APIs you are using I could try to make some suggestions.

As far as what a production build actually does… EmberCLI recognizes three actual environments for build: test, development, production. All builds take all of your js/css/htmlbars etc in app/ and smash it all together into app.js, vendor.js, app.css, vendor.css, and then link those files to the index.html (there’s some other files involved but that’s not that important atm). It stores these “compiled” assets in /dist/ by default. Production builds vary from development builds a lot, but in broad strokes they are usually minified, compressed, and often fingerprinted. I think production builds also usually include a lot less code from addons and such as well but that really depends.

3 Likes

There are three supported environments: development, test, and production. The way to think about them is:

  • development: running on your own machine
  • test: for test suites
  • production: running on a server

Any time you’re going to deploy an ember app to a server (whether that server is your “production” one or some staging one), --environment=production is the appropriate choice.

Production builds are smaller and faster. Dev builds include extra code for detecting possible problems and giving developers more helpful warnings and errors.

2 Likes