From 304266020d94ee2b498c508f361bbd91a5019678 Mon Sep 17 00:00:00 2001 From: Max S Date: Sat, 28 Dec 2024 17:20:15 +0000 Subject: [PATCH] Webpack compress with gzip and brotli --- package-lock.json | 22 ++++++++++++++++++++++ package.json | 1 + webpack.config.js | 17 +++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/package-lock.json b/package-lock.json index af5fd6dd2a..beee33094f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -118,6 +118,7 @@ "chromedriver": "^130.0.0", "cli-progress": "^3.12.0", "colors": "^1.4.0", + "compression-webpack-plugin": "^11.1.0", "copy-webpack-plugin": "^12.0.2", "core-js": "^3.37.1", "css-loader": "7.1.2", @@ -5344,6 +5345,27 @@ "node": ">= 0.8.0" } }, + "node_modules/compression-webpack-plugin": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/compression-webpack-plugin/-/compression-webpack-plugin-11.1.0.tgz", + "integrity": "sha512-zDOQYp10+upzLxW+VRSjEpRRwBXJdsb5lBMlRxx1g8hckIFBpe3DTI0en2w7h+beuq89576RVzfiXrkdPGrHhA==", + "dev": true, + "license": "MIT", + "dependencies": { + "schema-utils": "^4.2.0", + "serialize-javascript": "^6.0.2" + }, + "engines": { + "node": ">= 18.12.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" + }, + "peerDependencies": { + "webpack": "^5.1.0" + } + }, "node_modules/compression/node_modules/bytes": { "version": "3.0.0", "dev": true, diff --git a/package.json b/package.json index 54664eb16f..7901c8a415 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "chromedriver": "^130.0.0", "cli-progress": "^3.12.0", "colors": "^1.4.0", + "compression-webpack-plugin": "^11.1.0", "copy-webpack-plugin": "^12.0.2", "core-js": "^3.37.1", "css-loader": "7.1.2", diff --git a/webpack.config.js b/webpack.config.js index e77f2ab9cb..f23fab0e13 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,8 +1,10 @@ const webpack = require("webpack"); const MiniCssExtractPlugin = require("mini-css-extract-plugin"); +const CompressionPlugin = require("compression-webpack-plugin"); const CopyWebpackPlugin = require("copy-webpack-plugin"); const { ModifySourcePlugin, ReplaceOperation } = require("modify-source-webpack-plugin"); const path = require("path"); +const zlib = require("zlib"); /** * Webpack configuration details for use with Grunt. @@ -64,6 +66,21 @@ module.exports = { new MiniCssExtractPlugin({ filename: "assets/[name].css" }), + new CompressionPlugin({ + filename: "[path][base].gz", + algorithm: "gzip", + test: /\.(js|css|html)$/, + }), + new CompressionPlugin({ + filename: "[path][base].br", + algorithm: "brotliCompress", + test: /\.(js|css|html)$/, + compressionOptions: { + params: { + [zlib.constants.BROTLI_PARAM_QUALITY]: 11, + }, + }, + }), new CopyWebpackPlugin({ patterns: [ {