How to specify compression for custom build environment in Ember

吃可爱长大的小学妹 提交于 2019-12-20 03:42:32

问题


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

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

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'
}

command

ember build --environment=qa

回答1:


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 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.

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



来源:https://stackoverflow.com/questions/50993237/how-to-specify-compression-for-custom-build-environment-in-ember

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!