Skip to content

Instantly share code, notes, and snippets.

@rom3r4
Forked from aldo-roman/compress.js
Created January 6, 2021 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rom3r4/10b927db3c3d5543765d813d93bb3450 to your computer and use it in GitHub Desktop.
Save rom3r4/10b927db3c3d5543765d813d93bb3450 to your computer and use it in GitHub Desktop.
Brotli compression with Angular CLI
const brotli = require('brotli')
const fs = require('fs')
const brotliSettings = {
extension: 'br',
skipLarger: true,
mode: 1, // 0 = generic, 1 = text, 2 = font (WOFF2)
quality: 10, // 0 - 11,
lgwin: 12 // default
}
fs.readdirSync('dist/').forEach(file => {
if (file.endsWith('.js') || file.endsWith('.css') || file.endsWith('.html')) {
const result = brotli.compress(fs.readFileSync('dist/' + file), brotliSettings)
fs.writeFileSync('dist/' + file + '.br', result)
}
})
{
"name": "my-ng-cli-app",
"scripts": {
"build-prod": "ng build --prod && node compress.js"
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment