Skip to content

Commit

Permalink
Add compression to staging and production envs
Browse files Browse the repository at this point in the history
  • Loading branch information
martincik committed Apr 12, 2024
1 parent 845a7ef commit 432cb82
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"browserify-zlib": "^0.2.0",
"bs58": "^4.0.1",
"buffer": "^6.0.3",
"compression-webpack-plugin": "^11.1.0",
"copy-webpack-plugin": "^5.1.1",
"crypto-browserify": "^3.12.0",
"css-loader": "^3.4.2",
Expand Down
14 changes: 14 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const CopyPlugin = require("copy-webpack-plugin");
const StatoscopeWebpackPlugin = require("@statoscope/webpack-plugin").default;
const { DuplicatesPlugin } = require("inspectpack/plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CompressionPlugin = require("compression-webpack-plugin");

const bundleOutputDir = "./dist";

Expand Down Expand Up @@ -50,6 +51,7 @@ module.exports = (env) => {
];
break;
case "production":
devtool = false;
plugins = [
new Dotenv({
path: path.join(__dirname, ".env.production"),
Expand All @@ -64,6 +66,12 @@ module.exports = (env) => {
new MiniCssExtractPlugin({
filename: "[name].css",
}),
new CompressionPlugin({
test: /\.(js|css)$/, // Compress .js and .css files
algorithm: "gzip", // Default compression algorithm
threshold: 10240, // Only assets bigger than this size (10 Kilobytes) are processed
minRatio: 0.8 // Only assets that compress better than this ratio are processed
}),
];
break;
case "staging":
Expand All @@ -82,6 +90,12 @@ module.exports = (env) => {
new MiniCssExtractPlugin({
filename: "[name].css",
}),
new CompressionPlugin({
test: /\.(js|css)$/, // Compress .js and .css files
algorithm: "gzip", // Default compression algorithm
threshold: 10240, // Only assets bigger than this size (10 Kilobytes) are processed
minRatio: 0.8 // Only assets that compress better than this ratio are processed
}),
];
break;
default:
Expand Down
43 changes: 39 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -942,9 +942,9 @@
"@babel/plugin-transform-typescript" "^7.18.6"

"@babel/runtime@^7.12.5":
version "7.24.0"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.24.0.tgz#584c450063ffda59697021430cb47101b085951e"
integrity sha512-Chk32uHMg6TnQdvw2e9IlqPpFX/6NLuK0Ys2PqLb7/gL5uFn9mXvK715FGLlOLQrcO4qIkNHkvPGktzzXexsFw==
version "7.24.4"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.24.4.tgz#de795accd698007a66ba44add6cc86542aff1edd"
integrity sha512-dkxf7+hn8mFBwKjs9bvBlArzLVxVbS8usaPUDd5p2a9JCL9tB8OaOVN1isD4+Xyk4ns89/xeOmbQvgdK7IIVdA==
dependencies:
regenerator-runtime "^0.14.0"

Expand Down Expand Up @@ -3580,7 +3580,7 @@ ajv-keywords@^3.1.0, ajv-keywords@^3.5.2:
resolved "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.5.2.tgz"
integrity sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==

ajv-keywords@^5.0.0:
ajv-keywords@^5.0.0, ajv-keywords@^5.1.0:
version "5.1.0"
resolved "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-5.1.0.tgz"
integrity sha512-YCS/JNFAUyr5vAuhk1DWm1CBxRHW9LbJ2ozWeemrIqpbsqKjHVxYPyi5GC0rjZIT5JxJ3virVTS8wk4i/Z+krw==
Expand All @@ -3607,6 +3607,16 @@ ajv@^8.0.0, ajv@^8.8.0:
require-from-string "^2.0.2"
uri-js "^4.2.2"

ajv@^8.9.0:
version "8.12.0"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.12.0.tgz#d1a0527323e22f53562c567c00991577dfbe19d1"
integrity sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==
dependencies:
fast-deep-equal "^3.1.1"
json-schema-traverse "^1.0.0"
require-from-string "^2.0.2"
uri-js "^4.2.2"

[email protected]:
version "4.1.1"
resolved "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz"
Expand Down Expand Up @@ -4544,6 +4554,14 @@ compressible@~2.0.16:
dependencies:
mime-db ">= 1.43.0 < 2"

compression-webpack-plugin@^11.1.0:
version "11.1.0"
resolved "https://registry.yarnpkg.com/compression-webpack-plugin/-/compression-webpack-plugin-11.1.0.tgz#ee340d2029cf99ccecdea9ad1410b377d15b48b3"
integrity sha512-zDOQYp10+upzLxW+VRSjEpRRwBXJdsb5lBMlRxx1g8hckIFBpe3DTI0en2w7h+beuq89576RVzfiXrkdPGrHhA==
dependencies:
schema-utils "^4.2.0"
serialize-javascript "^6.0.2"

compression@^1.7.4:
version "1.7.4"
resolved "https://registry.npmjs.org/compression/-/compression-1.7.4.tgz"
Expand Down Expand Up @@ -8663,6 +8681,16 @@ schema-utils@^4.0.0:
ajv-formats "^2.1.1"
ajv-keywords "^5.0.0"

schema-utils@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-4.2.0.tgz#70d7c93e153a273a805801882ebd3bff20d89c8b"
integrity sha512-L0jRsrPpjdckP3oPug3/VxNKt2trR8TcabrM6FOAAlvC/9Phcmm+cuAgTlxBqdBR1WJx7Naj9WHw+aOmheSVbw==
dependencies:
"@types/json-schema" "^7.0.9"
ajv "^8.9.0"
ajv-formats "^2.1.1"
ajv-keywords "^5.1.0"

sdp@^2.12.0, sdp@^2.6.0:
version "2.12.0"
resolved "https://registry.npmjs.org/sdp/-/sdp-2.12.0.tgz"
Expand Down Expand Up @@ -8745,6 +8773,13 @@ serialize-javascript@^4.0.0:
dependencies:
randombytes "^2.1.0"

serialize-javascript@^6.0.2:
version "6.0.2"
resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-6.0.2.tgz#defa1e055c83bf6d59ea805d8da862254eb6a6c2"
integrity sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g==
dependencies:
randombytes "^2.1.0"

serve-index@^1.9.1:
version "1.9.1"
resolved "https://registry.npmjs.org/serve-index/-/serve-index-1.9.1.tgz"
Expand Down

0 comments on commit 432cb82

Please sign in to comment.