简体   繁体   English

ember-cli-build.js | 根据环境设置西兰花的参数

[英]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.

相关问题 在ember-cli-build.js中自动引用Bower包 - Automatically reference bower package in ember-cli-build.js 如何从 ember-cli-build.js 访问环境参数 - How to access the environment parameter from ember-cli-build.js 如何在ember-cli-build.js中基于环境配置ember-cli-babel? - how to configure ember-cli-babel based on environment in ember-cli-build.js? 树:{ember-cli-build.js中的{mergetrees(['src',external js file])}}无法正常工作 - trees:{ mergetrees(['src',external js file])} in ember-cli-build.js is not working 无法通过ember-cli-build.js加载bootstrap js - Can't load bootstrap js via ember-cli-build.js Ember-cli构建错误-Broccoli插件:[broccoli-persistent-filter:TemplateCompiler]失败,原因是: - Ember-cli build error— The Broccoli Plugin: [broccoli-persistent-filter:TemplateCompiler] failed with: ember cli应用程序构建失败:Broccoli插件:[object Object]失败: - ember cli application build fails: The Broccoli Plugin: [object Object] failed with: Ember js 构建错误 (broccoli-persistent-filter:EslintValidationFilter) - Ember js Build Error (broccoli-persistent-filter:EslintValidationFilter) 在Ember CLI Project中使用Broccoli JS移动整个文件夹 - Move Entire Folder using Broccoli JS in Ember CLI Project Ember Cli不使用西兰花汇编汇编程序进行编译 - Ember Cli not compiling with broccoli-emblem-compiler
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM