Skip to content

Commit

Permalink
Add brotli compression when natively supported
Browse files Browse the repository at this point in the history
  • Loading branch information
clupprich committed Sep 6, 2019
1 parent d0fa1d1 commit d5b9fdc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -44,6 +44,7 @@
"postcss-safe-parser": "^4.0.1",
"regenerator-runtime": "^0.13.2",
"sass-loader": "^7.1.0",
"semver": "^6.3.0",
"style-loader": "^0.23.1",
"terser-webpack-plugin": "^1.3.0",
"webpack": "^4.32.2",
Expand Down
14 changes: 14 additions & 0 deletions package/environments/production.js
Expand Up @@ -2,6 +2,7 @@ const TerserPlugin = require('terser-webpack-plugin')
const CompressionPlugin = require('compression-webpack-plugin')
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const safePostCssParser = require('postcss-safe-parser')
const semver = require('semver')
const Base = require('./base')

module.exports = class extends Base {
Expand All @@ -18,6 +19,19 @@ module.exports = class extends Base {
})
)

// Brotli is part of node's zlib library since 11.7.0
if (semver.satisfies(process.versions.node, '>=11.7.0')) {
this.plugins.append(
'Compression Brotli',
new CompressionPlugin({
filename: '[path].br[query]',
algorithm: 'brotliCompress',
cache: true,
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf|map)$/
})
)
}

this.plugins.append(
'OptimizeCSSAssets',
new OptimizeCSSAssetsPlugin({
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -6853,6 +6853,11 @@ semver@^6.0.0, semver@^6.1.0:
resolved "https://registry.yarnpkg.com/semver/-/semver-6.1.0.tgz#e95dc415d45ecf03f2f9f83b264a6b11f49c0cca"
integrity sha512-kCqEOOHoBcFs/2Ccuk4Xarm/KiWRSLEX9CAZF8xkJ6ZPlIoTZ8V5f7J16vYLJqDbR7KrxTJpR2lqjIEm2Qx9cQ==

semver@^6.3.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==

semver@~5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"
Expand Down

0 comments on commit d5b9fdc

Please sign in to comment.