问题
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