如何在Ember中为自定义构建环境指定压缩 [英] How to specify compression for custom build environment in Ember

查看:75
本文介绍了如何在Ember中为自定义构建环境指定压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为自定义环境指定压缩,捆绑和在文件名中添加无效哈希?

How do I specify compression, bundling and adding invalidation hashes to filenames for a custom environment?

生产环境将自动压缩和合并文件,并向其中添加无效哈希文件名。即每当我使用 ember build --environment = production 触发 if(environment ==='production'){} config / environment.js

The production environment will automatically compress and consolidate files and add invalidation hashes to the file names. I.e. whenever I use ember build --environment=production to trigger the if (environment === 'production'){} case in config/environment.js

但是我想为也压缩的QA环境创建和构建文件,并在文件名中添加无效哈希。即以下代码也应生成以无效哈希命名的压缩文件(输出与 production 输出相同,除了带有QA变量(如URL)外)

But I want to create and build for a QA environment that also compresses files and adds invalidation hashes to file names. I.e. the following should also produce compressed files named with invalidation hashes (output the same as what production outputs except with QA variables, like URLs):

config / environment.js

if (environment === `qa`){
    ENV.somevar = 'qa-value'
}

命令

ember build --environment=qa


推荐答案

这是在 ember-cli-build.js 您的项目文件。默认情况下,仅在生产环境中启用指纹识别( app.env ===生产 )。可以通过 fingerprint.enabled 选项进行更改。 ember-cli-uglify 用于JavaScript压缩和 minifyCSS 选项也是如此。根据需要配置以下选项:

This is configured in ember-cli-build.js file of your project. By default fingerprinting is only enabled in production (app.env === 'production'). This could be changed by fingerprint.enabled option. The same applies to ember-cli-uglify for JavaScript minification and minifyCSS options. Configure these options as required:

'use strict';

const EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function(defaults) {
  let env = EmberApp.env();
  let isProductionLike = ['production', 'qa'].includes(env);
  let app = new EmberApp({
    'ember-cli-uglify': {
      enabled: isProductionLike
    },
    fingerprint: {
      enabled: isProductionLike
    },
    minifyCSS: {
      enabled: isProductionLike
    },
    sourcemaps: {
      enabled: !isProductionLike
    }
  });

  return app.toTree();
};

ember-cli-uglify 选项已命名ember-cli-uglify 1.x中的 minifyJS 。该插件已在ember-cli 2.16的默认蓝图中进行了更新。如果您仍在使用ember-cli-uglify@1.x,请相应地更改选项名称。在撰写此答案时,ember-cli文档尚未反映出这一重大变化。它是在此处引入的。另请注意,有一个公开问题,因此可能

ember-cli-uglify option was named minifyJS in ember-cli-uglify 1.x. The addon was updated in default blueprint of ember-cli 2.16. Change option name accordingly if you are still using ember-cli-uglify@1.x. At the point of time writing this answer, ember-cli docs had not yet reflected that breaking change. It was introduced here. Also note that there is an open issue about it, so it might change in the future again.

更多详细信息和选项可在 ember-cli文档的资产编译章节

More details and options are available in asset compilation chapter of ember-cli docs.

这篇关于如何在Ember中为自定义构建环境指定压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆