A Karma preprocessor for compressing test assets.
Particularly handy when working with large test bundles and remote browser-cloud services like Browserstack or Saucelabs.
npm install karma-gzip-preprocessor --save-dev
Since karma-gzip-preprocessor has a minimum requirement of karma v3.1.0.
For older versions of karma, see the README for karma-gzip v2.
To enable gzip compression, all you need to do is add gzip
as a preprocessor in your karma config.
// karma.conf.js
module.exports = function(config) {
config.set({
files: [
'src/**/*.test.js'
],
// The plugins config property is optional, but if it is included it must include 'karma-gzip-preprocessor'
plugins: [
'karma-gzip-preprocessor',
],
preprocessors: {
'src/**/*.js': ['gzip'],
// The `gzip` preprocessor should always be the last preprocessor
'*.coffee': ['coffee', 'gzip'],
},
});
};
Verify your assets are gzipped when you see output simmilar to the following:
$ karma start
INFO [preprocessor.gzip]: compressed /MyProject/src/polyfills.js [2MB -> 437KB]
INFO [preprocessor.gzip]: compressed /MyProject/src/index.test.js [5MB -> 1MB]