diff options
author | Kristóf Marussy <kristof@marussy.com> | 2024-03-21 00:07:57 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2024-03-21 12:00:48 +0100 |
commit | 6751c44622ad722f2924bd9a91146129b06545de (patch) | |
tree | 6bea8e38e89cbd9b26c236701307b483487c1caa | |
parent | Fix PostCSS warning (diff) | |
download | blog-6751c44622ad722f2924bd9a91146129b06545de.tar.gz blog-6751c44622ad722f2924bd9a91146129b06545de.tar.zst blog-6751c44622ad722f2924bd9a91146129b06545de.zip |
Add static asset compression
-rw-r--r-- | docusaurus.config.ts | 1 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | src/plugins/compressionPlugin.ts | 42 | ||||
-rw-r--r-- | yarn.lock | 23 |
4 files changed, 62 insertions, 5 deletions
diff --git a/docusaurus.config.ts b/docusaurus.config.ts index bb5be9c..f19513a 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts | |||
@@ -24,6 +24,7 @@ export default { | |||
24 | }, | 24 | }, |
25 | ], | 25 | ], |
26 | '@docusaurus/plugin-sitemap', | 26 | '@docusaurus/plugin-sitemap', |
27 | './src/plugins/compressionPlugin.ts', | ||
27 | './src/plugins/responsiveLoaderPlugin.ts', | 28 | './src/plugins/responsiveLoaderPlugin.ts', |
28 | './src/plugins/swcMinifyPlugin.ts', | 29 | './src/plugins/swcMinifyPlugin.ts', |
29 | './src/plugins/thirdPartyContentPlugin.ts', | 30 | './src/plugins/thirdPartyContentPlugin.ts', |
diff --git a/package.json b/package.json index 8008fb5..05e7ffa 100644 --- a/package.json +++ b/package.json | |||
@@ -36,6 +36,7 @@ | |||
36 | "@phosphor-icons/react": "2.0.15", | 36 | "@phosphor-icons/react": "2.0.15", |
37 | "@swc/core": "^1.4.8", | 37 | "@swc/core": "^1.4.8", |
38 | "clsx": "^2.1.0", | 38 | "clsx": "^2.1.0", |
39 | "compression-webpack-plugin": "^11.1.0", | ||
39 | "prop-types": "^15.8.1", | 40 | "prop-types": "^15.8.1", |
40 | "react": "^18.2.0", | 41 | "react": "^18.2.0", |
41 | "react-dom": "^18.2.0", | 42 | "react-dom": "^18.2.0", |
diff --git a/src/plugins/compressionPlugin.ts b/src/plugins/compressionPlugin.ts new file mode 100644 index 0000000..b1cff6a --- /dev/null +++ b/src/plugins/compressionPlugin.ts | |||
@@ -0,0 +1,42 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2024 Kristóf Marussy <kristof@marussy.com> | ||
3 | * | ||
4 | * SPDX-License-Identifier: MIT | ||
5 | */ | ||
6 | |||
7 | import zlib, { type BrotliOptions } from 'node:zlib'; | ||
8 | |||
9 | import type { Plugin } from '@docusaurus/types'; | ||
10 | import CompressionPlugin from 'compression-webpack-plugin'; | ||
11 | |||
12 | const test = /\.(js|css|html|svg|txt)$/; | ||
13 | |||
14 | export default function compressionPlugin(): Plugin { | ||
15 | return { | ||
16 | name: 'marussy-compression-plugin', | ||
17 | configureWebpack: (_config, isServer) => | ||
18 | isServer | ||
19 | ? {} | ||
20 | : { | ||
21 | plugins: [ | ||
22 | new CompressionPlugin({ | ||
23 | test, | ||
24 | filename: '[path][base].gz', | ||
25 | compressionOptions: { | ||
26 | level: 9, | ||
27 | }, | ||
28 | }), | ||
29 | new CompressionPlugin<BrotliOptions>({ | ||
30 | test, | ||
31 | filename: '[path][base].br', | ||
32 | algorithm: 'brotliCompress', | ||
33 | compressionOptions: { | ||
34 | params: { | ||
35 | [zlib.constants.BROTLI_PARAM_QUALITY]: 11, | ||
36 | }, | ||
37 | }, | ||
38 | }), | ||
39 | ], | ||
40 | }, | ||
41 | }; | ||
42 | } | ||
@@ -4343,6 +4343,18 @@ __metadata: | |||
4343 | languageName: node | 4343 | languageName: node |
4344 | linkType: hard | 4344 | linkType: hard |
4345 | 4345 | ||
4346 | "compression-webpack-plugin@npm:^11.1.0": | ||
4347 | version: 11.1.0 | ||
4348 | resolution: "compression-webpack-plugin@npm:11.1.0" | ||
4349 | dependencies: | ||
4350 | schema-utils: "npm:^4.2.0" | ||
4351 | serialize-javascript: "npm:^6.0.2" | ||
4352 | peerDependencies: | ||
4353 | webpack: ^5.1.0 | ||
4354 | checksum: 10c0/387043d1e7dd776768bbc92071953ae0459891337f1ca908c0b4c9fe98322caf19847fae3713876e3976d894599712f784ccf13baa6d1c64ecb915786a54f2ec | ||
4355 | languageName: node | ||
4356 | linkType: hard | ||
4357 | |||
4346 | "compression@npm:^1.7.4": | 4358 | "compression@npm:^1.7.4": |
4347 | version: 1.7.4 | 4359 | version: 1.7.4 |
4348 | resolution: "compression@npm:1.7.4" | 4360 | resolution: "compression@npm:1.7.4" |
@@ -7500,6 +7512,7 @@ __metadata: | |||
7500 | "@types/node": "npm:^20.11.30" | 7512 | "@types/node": "npm:^20.11.30" |
7501 | "@types/react": "npm:^18.2.67" | 7513 | "@types/react": "npm:^18.2.67" |
7502 | clsx: "npm:^2.1.0" | 7514 | clsx: "npm:^2.1.0" |
7515 | compression-webpack-plugin: "npm:^11.1.0" | ||
7503 | cross-env: "npm:^7.0.3" | 7516 | cross-env: "npm:^7.0.3" |
7504 | prettier: "npm:^3.2.5" | 7517 | prettier: "npm:^3.2.5" |
7505 | prop-types: "npm:^15.8.1" | 7518 | prop-types: "npm:^15.8.1" |
@@ -10518,7 +10531,7 @@ __metadata: | |||
10518 | languageName: node | 10531 | languageName: node |
10519 | linkType: hard | 10532 | linkType: hard |
10520 | 10533 | ||
10521 | "schema-utils@npm:^4.0.0": | 10534 | "schema-utils@npm:^4.0.0, schema-utils@npm:^4.2.0": |
10522 | version: 4.2.0 | 10535 | version: 4.2.0 |
10523 | resolution: "schema-utils@npm:4.2.0" | 10536 | resolution: "schema-utils@npm:4.2.0" |
10524 | dependencies: | 10537 | dependencies: |
@@ -10606,12 +10619,12 @@ __metadata: | |||
10606 | languageName: node | 10619 | languageName: node |
10607 | linkType: hard | 10620 | linkType: hard |
10608 | 10621 | ||
10609 | "serialize-javascript@npm:^6.0.0, serialize-javascript@npm:^6.0.1": | 10622 | "serialize-javascript@npm:^6.0.0, serialize-javascript@npm:^6.0.1, serialize-javascript@npm:^6.0.2": |
10610 | version: 6.0.1 | 10623 | version: 6.0.2 |
10611 | resolution: "serialize-javascript@npm:6.0.1" | 10624 | resolution: "serialize-javascript@npm:6.0.2" |
10612 | dependencies: | 10625 | dependencies: |
10613 | randombytes: "npm:^2.1.0" | 10626 | randombytes: "npm:^2.1.0" |
10614 | checksum: 10c0/1af427f4fee3fee051f54ffe15f77068cff78a3c96d20f5c1178d20630d3ab122d8350e639d5e13cde8111ef9db9439b871305ffb185e24be0a2149cec230988 | 10627 | checksum: 10c0/2dd09ef4b65a1289ba24a788b1423a035581bef60817bea1f01eda8e3bda623f86357665fe7ac1b50f6d4f583f97db9615b3f07b2a2e8cbcb75033965f771dd2 |
10615 | languageName: node | 10628 | languageName: node |
10616 | linkType: hard | 10629 | linkType: hard |
10617 | 10630 | ||