After long searches and good examples, here's what I did.
Assuming you are using yoman using the forest using the yo ember generator and using grunt build to create dist.
Yo ember-generator v0.8 uses grunt-replace. Update this version. In short, I use grunt-replace to add global vars to index.html. Here is how.
Add this script tag to app / index.html before the combined scripts.js block:
#app/index.html <script> window.MYCOMPANYCOM_ENV = { env: '@@env', apiHost: '@@apiHost' }; </script> /* ADD THE ABOVE BEFORE THIS SECTION */ <script src="scripts/combined-scripts.js"></script>
And change the replacement configuration in the Gruntfile.js file to the following:
module.exports = function (grunt) { var appConfig = grunt.file.readJSON('app_config.json'); replace: { app: { options: { patterns: [ { json: appConfig['app'] } ] }, files: [ {src: '<%= yeoman.app %>/index.html', dest: '.tmp/index.html'} ] }, dist: { options: { patterns: [ { json: appConfig['dist'] } ] }, files: [ {src: '<%= yeoman.dist %>/index.html', dest: '<%= yeoman.dist %>/index.html'} ] } }
Create a new file in. / app _config.json
{ "app": { "env": "development", "apiHost": "http://localhost:8080" }, "dist": { "env": "dist", "apiHost": "/" } }
Your application scripts now have access to the global vars defined in app_config.json.
I will not go into details, but it works great in development. For grunt build I moved the replace:dist step to the end of the build steps and replaced the @@ ember variable in index.html with the path to the bower component.
source share