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

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

问题描述

如何为自定义环境指定压缩、捆绑和向文件名添加失效哈希?

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

生产环境将自动压缩和合并文件,并为文件名添加失效哈希.IE.每当我使用 ember build --environment=productionconfig/environment.js<中触发 if (environment === 'production'){} 案例时/代码>

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 环境创建和构建,该环境还压缩文件并向文件名添加失效哈希.IE.以下还应生成以失效哈希命名的压缩文件(输出与 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 === 'production').这可以通过 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 文档的资产编译章节中提供了更多详细信息和选项.

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

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