[英]ember-cli-build.js | set broccoli's params depending on environmnet
I tried to search in google this but without the correct answer if I need to do. 我试图在谷歌搜索此,但没有正确的答案,如果我需要这样做。
It's a simple question I have my ember-cli-build.js 这是一个简单的问题,我有我的ember-cli-build.js
/*jshint node:true*/
/* global require, module */
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
module.exports = function(defaults) {
var app = new EmberApp(defaults, {
storeConfigInMeta: false,
minifyJS: {
enabled: false
},
minifyCSS: {
enabled: false
}
});
return app.toTree();
};
And I want change the value of minifyJS or minifyCSS depending on whether I am running ember in production or dev - how can achieve that? 我想根据是在生产环境还是在开发环境中运行ember来更改minifyJS或minifyCSS的值-如何实现?
This answer applies to Ember 2.xx and was written as of 2.15. 此答案适用于Ember 2.xx,撰写于2.15。
In your ember-cli-build.js
you can do EmberApp.env()
to get the environment. 在
ember-cli-build.js
您可以执行EmberApp.env()
来获取环境。 You could also do process.env.EMBER_ENV
but the first option is in the Ember CLI Docs , so I'd go with that personally. 您也可以执行
process.env.EMBER_ENV
但第一个选项位于Ember CLI Docs中 ,所以我个人考虑一下。
Example: 例:
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
module.exports = function(defaults) {
var enableMin = (EmberApp.env() === 'production');
var app = new EmberApp(defaults, {
storeConfigInMeta: false,
minifyJS: {
enabled: enableMin
},
minifyCSS: {
enabled: enableMin
}
});
return app.toTree();
};
According to EmberCLI docs: Fingerprinting and CDN URLs also app.env
property should be available and the following code should be fine, too: 根据EmberCLI docs: 指纹和CDN URL以及
app.env
属性也应该可用,并且以下代码也可以:
module.exports = function (defaults) {
const app = new EmberApp(defaults, {});
if (app.env === 'development') {
// do something specific for dev
} else if (app.env === 'production') {
// do something specific for prod
}
};
Note: app.env
holds "test"
when building for testing purposes. 注意:为测试目的而构建时,
app.env
持有"test"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.