» ember --version
version: 1.13.13
node: 0.12.2
npm: 2.14.10
os: linux x64
My application needs to be aware of the STATIC_URL where it is being deployed (which depends on the deploy environment “development” / “production”) at two different stages:
when building the application, in order to use the right fingerprint prepend
on the client application, in order to prefix static assets with the right url
First I thought about defining a STATIC_URL variable on config/environment.js (where I have access to the environment parameter), and then do in ember-cli-build.js:
// TODO: This does not work
import config from './config/environment';
module.exports = function(defaults) {
var app = new EmberApp(defaults, {
fingerprint: {
enabled: true,
prepend: config.STATIC_URL,
},
});
return app.toTree();
};
But I am unable to import the config environment:
import config from './config/environment';
^^^^^^
Unexpected reserved word
Probably what I am trying to do does not make much sense (passing values upwards from config/environment.js → ember-cli-build.js). So instead of that, what I need is:
Access the build environment parameter (“development” / “production”) from ember-cli-build.js. This should be already available, since the ember-cli guide specifies that fingerprinting is by default only available in production: app.env === 'production'. But I need to access app.env before app is even defined. How to do that?
Configure a STATIC_URL
Pass the STATIC_URL parameter down to config/environment.js (to avoid reconfiguring it again for the client application)
var config = defaults.project.config(process.env.EMBER_ENV || 'development');
console.log(config.STATIC_URL);
This should do it, I don’t know of a public API way of doing this since you need it before the app is initialized. But this will get you what you need.
Cleaning up my previous posts so I don’t confuse future travelers
Yeah, my previous responses, which I deleted, included attempts to use EmberApp.env() but it would occasionally return undefined and in one instance throw on EmberApp.env is not a function.