From 923eeaa4cc1c8b9ba941a9f0ca0cf6be4dee2451 Mon Sep 17 00:00:00 2001
From: ThatOneCalculator <kainoa@t1c.dev>
Date: Sun, 19 Mar 2023 00:26:26 -0700
Subject: [PATCH] feat: compile time compression

---
 CALCKEY.md                     |  2 ++
 packages/client/package.json   |  1 +
 packages/client/vite.config.ts |  4 ++++
 pnpm-lock.yaml                 | 39 +++++++++++++++++++++++++++++++++-
 4 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/CALCKEY.md b/CALCKEY.md
index 110aaf264..66c6e8d42 100644
--- a/CALCKEY.md
+++ b/CALCKEY.md
@@ -112,6 +112,8 @@
 - More antenna options
 - New dashboard
 - Backfill follower counts
+- Improved emoji licensing
+- Compile time compression
 - MissV: [fix Misskey Forkbomb](https://code.vtopia.live/Vtopia/MissV/commit/40b23c070bd4adbb3188c73546c6c625138fb3c1)
 - [Make showing ads optional](https://github.com/misskey-dev/misskey/pull/8996)
 - [Tapping avatar in mobile opens account modal](https://github.com/misskey-dev/misskey/pull/9056)
diff --git a/packages/client/package.json b/packages/client/package.json
index 1f3270b1d..be7538542 100644
--- a/packages/client/package.json
+++ b/packages/client/package.json
@@ -78,6 +78,7 @@
 		"uuid": "9.0.0",
 		"vanilla-tilt": "1.8.0",
 		"vite": "^4.1.1",
+		"vite-plugin-compression": "^0.5.1",
 		"vue": "3.2.45",
 		"vue-isyourpasswordsafe": "^2.0.0",
 		"vue-plyr": "^7.0.0",
diff --git a/packages/client/vite.config.ts b/packages/client/vite.config.ts
index 7644ccaa0..f4d04e5ec 100644
--- a/packages/client/vite.config.ts
+++ b/packages/client/vite.config.ts
@@ -5,6 +5,7 @@ import { defineConfig } from 'vite';
 import locales from '../../locales';
 import meta from '../../package.json';
 import pluginJson5 from './vite.json5';
+import viteCompression from 'vite-plugin-compression';
 
 const extensions = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.json', '.json5', '.svg', '.sass', '.scss', '.css', '.vue'];
 
@@ -20,6 +21,9 @@ export default defineConfig(({ command, mode }) => {
 				reactivityTransform: true,
 			}),
 			pluginJson5(),
+			viteCompression({
+				algorithm: 'brotliCompress'
+			}),
 		],
 
 		resolve: {
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index c1a00fbfd..de1200477 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -465,6 +465,7 @@ importers:
       uuid: 9.0.0
       vanilla-tilt: 1.8.0
       vite: ^4.1.1
+      vite-plugin-compression: ^0.5.1
       vue: 3.2.45
       vue-isyourpasswordsafe: ^2.0.0
       vue-plyr: ^7.0.0
@@ -542,6 +543,7 @@ importers:
       uuid: 9.0.0
       vanilla-tilt: 1.8.0
       vite: 4.1.1_sass@1.57.1
+      vite-plugin-compression: 0.5.1_vite@4.1.1
       vue: 3.2.45
       vue-isyourpasswordsafe: 2.0.0
       vue-plyr: 7.0.0
@@ -3402,7 +3404,7 @@ packages:
   /axios/0.25.0_debug@4.3.4:
     resolution: {integrity: sha512-cD8FOb0tRH3uuEe6+evtAbgJtfxr7ly3fQjYcMcuPlgkwVS9xboaVIpcDV+cYQe+yGykgwZCs1pzjntcGa6l5g==}
     dependencies:
-      follow-redirects: 1.15.2
+      follow-redirects: 1.15.2_debug@4.3.4
     transitivePeerDependencies:
       - debug
     dev: true
@@ -6407,6 +6409,19 @@ packages:
     peerDependenciesMeta:
       debug:
         optional: true
+    dev: false
+
+  /follow-redirects/1.15.2_debug@4.3.4:
+    resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==}
+    engines: {node: '>=4.0'}
+    peerDependencies:
+      debug: '*'
+    peerDependenciesMeta:
+      debug:
+        optional: true
+    dependencies:
+      debug: 4.3.4
+    dev: true
 
   /for-each/0.3.3:
     resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==}
@@ -6501,6 +6516,15 @@ packages:
   /fs-constants/1.0.0:
     resolution: {integrity: sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==}
 
+  /fs-extra/10.1.0:
+    resolution: {integrity: sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==}
+    engines: {node: '>=12'}
+    dependencies:
+      graceful-fs: 4.2.10
+      jsonfile: 6.1.0
+      universalify: 2.0.0
+    dev: true
+
   /fs-extra/8.1.0:
     resolution: {integrity: sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==}
     engines: {node: '>=6 <7 || >=8'}
@@ -12909,6 +12933,19 @@ packages:
       replace-ext: 1.0.1
     dev: true
 
+  /vite-plugin-compression/0.5.1_vite@4.1.1:
+    resolution: {integrity: sha512-5QJKBDc+gNYVqL/skgFAP81Yuzo9R+EAf19d+EtsMF/i8kFUpNi3J/H01QD3Oo8zBQn+NzoCIFkpPLynoOzaJg==}
+    peerDependencies:
+      vite: '>=2.0.0'
+    dependencies:
+      chalk: 4.1.2
+      debug: 4.3.4
+      fs-extra: 10.1.0
+      vite: 4.1.1_sass@1.57.1
+    transitivePeerDependencies:
+      - supports-color
+    dev: true
+
   /vite/4.1.1_sass@1.57.1:
     resolution: {integrity: sha512-LM9WWea8vsxhr782r9ntg+bhSFS06FJgCvvB0+8hf8UWtvaiDagKYWXndjfX6kGl74keHJUcpzrQliDXZlF5yg==}
     engines: {node: ^14.18.0 || >=16.0.0}