Last active
February 27, 2020 16:36
-
-
Save SergioGeeK7/ad3115486e84a82be0856ba25b46e15d to your computer and use it in GitHub Desktop.
Webpack gzip and brotli compression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// next.config.js | |
const webpack = require('webpack'); | |
const BrotliPlugin = require("brotli-webpack-plugin"); | |
const CompressionPlugin = require("compression-webpack-plugin"); | |
const isNodeDevelopment = process.env.NODE_ENV === "development" | |
module.exports = { | |
webpack: config => { | |
// Fixes npm packages that depend on `fs` module | |
// eslint-disable-next-line no-param-reassign | |
config.node = { | |
fs: "empty" | |
}; | |
if(!isNodeDevelopment){ | |
config.plugins.push( | |
new BrotliPlugin({ | |
asset: '[path].br[query]', | |
test: /\.js$|\.css$|\.html$|\.svg$/, | |
threshold: 10240, | |
minRatio: 0.8 | |
}) | |
); | |
config.plugins.push( | |
new CompressionPlugin({ | |
filename: "[path].gz[query]", | |
algorithm: "gzip", | |
test: /\.js$|\.css$|\.html$|\.svg$/, | |
threshold: 10240, | |
minRatio: 0.8 | |
}) | |
); | |
} | |
return config; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment