在我们的Brocfile.js中(我想您的名字叫ember-cli-build.js?),我们正在做这样的事情:
var EmberApp = require('ember-cli/broccoli/ember-app'); var environment = process.env.EMBER_ENV || 'development'; var config = require('./config/environment')(environment); var app = new EmberApp(/* configuration for the app... */ ); module.exports = app.toTree();
我们分配给环境变量的那一行是如何获取您所处的环境。我们使用EMBER_ENV命令行变量,但可以使用其他变量。基本上在我们所有的代码中,我们都是这样运行ember的:
EMBER_ENV=production ember-cli start EMBER_ENV=test ember-cli test # the next lines use the same 'development' environment EMBER_ENV=development ember-cli start ember-cli start
我正在使用Ember 2.5。要从ember-cli-build.js访问环境参数,请使用process.env.EMBER_ENV
。这是我的ember-cli-build.js:
let EmberApp = require('ember-cli/lib/broccoli/ember-app'); module.exports = function(defaults) { let app = getApp(defaults, process.env.EMBER_ENV); // Use `app.import` to add additional libraries to the generated // output files. return app.toTree(); }; function getApp(defaults, environment) { switch(environment) { case "production": return new EmberApp(defaults, { fingerprint: { enabled: true }, }); default: return new EmberApp(defaults, { fingerprint: { enabled: false }, }); } }