Publishing your app

In previous articles, we created an application and served it locally using a development server. Once you're satisfied with your app and are ready to release it to the public, you'll need to host it someplace where others can access it. This article covers the steps needed to build an Ember app for production, and publish it on GitHub as an easy test mechanism.

If you are comfortable with using GitHub, one great option for hosting your application (especially if you want to put it up somewhere for others to test) is GitHub Pages. Using our World Clock application as an example, we'll build our files for production and commit them to a gh-pages branch in our git repo.

Note: If you are looking for information about publishing Firefox OS apps and the Firefox Markerplace, go over to our Firefox Marketplace zone.

Getting your Ember application ready for publication

During development, Ember CLI continuously built our files and served them on our local server when we used the ember serve command. This build process was optimized for debugging and iterating on our application. However, we now want a build process optimized for production (e.g., file minification, fingerprinting, portable code). Fortunately, Ember CLI handles most of this for you. We just need to set some configuration options and run a build command specifically for a production environment.

In your project directory, navigate to the /config/environment.js file. At the bottom of this file, you'll see an if block where you can set configuration options for the production environment.

In this block, we want to set ENV.locationType to hash. This will ensure that Ember CLI appropriately handles the URLs for our application's assets when we publish them. Update the bottom code block to the following:

if (environment === 'production') {
  ENV.locationType = 'hash';
}

Next, go to your terminal or command line, and run the following build command in the root of your app:

ember build --environment=production

Assuming the application built successfully, you'll see in the /dist directory that all of your files are minified and fingerprinted — optimized for production. These are the only files we'll need to upload when we publish our app.

Uploading to GitHub

The next stage is to upload your app to GitHub and publish it on there (Publishing via GitHub provides a basic guide if you need it.)

You can either create a new repo for the production version of your code, or keep the development version and production version on different branches of the same repo. It's up to you. We like the second option better, as it allows you to share the development with others, and not just the end result. The steps below cover this second option.

  1. Create a new GitHub repo and upload your development code to the master branch.
  2. Create a new branch in your git repo called gh-pages. Make sure you have this new branch locally as well as remotely (run git pull if you created the new branch using GitHub's web interface, etc.)
  3. Checkout your new gh-pages branch. Within this branch, you only need the files that are in the /dist directory. Move these files up to the root of your project, and remove everything else (see an example here.)
  4. Commit these changes and push them up to the gh-pages branch on your remote repository. Your application will now be available at http://<your-github-username>.github.io/<your-application-name>/

Document Tags and Contributors

 Contributors to this page: dustinryerson, chrisdavidmills, kscarfone
 Last updated by: dustinryerson,