Skip to content

Instantly share code, notes, and snippets.

@SergioGeeK7
Last active February 27, 2020 16:36
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 SergioGeeK7/ad3115486e84a82be0856ba25b46e15d to your computer and use it in GitHub Desktop.
Save SergioGeeK7/ad3115486e84a82be0856ba25b46e15d to your computer and use it in GitHub Desktop.
Webpack gzip and brotli compression
// 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