Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 8dbf216

Browse files
committed
Compression
1 parent 06033de commit 8dbf216

File tree

4 files changed

+123
-1
lines changed

4 files changed

+123
-1
lines changed

package-lock.json

Lines changed: 107 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"rollup-plugin-import-map": "3.0.0",
4242
"vite": "3.2.4",
4343
"vite-plugin-environment": "1.1.3",
44+
"vite-plugin-compression": "0.5.1",
4445
"vite-plugin-mock": "2.9.6",
4546
"vitest": "0.25.2"
4647
},

server/server.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@ const cors = require("cors");
33
const path = require("path");
44
const basePath = "/tms-min-side-varslinger";
55
const buildPath = path.resolve(__dirname, "../dist");
6+
const expressStaticGzip = require("express-static-gzip");
67
const server = express();
78
const corsAllowedOrigin = process.env.CORS_ALLOWED_ORIGIN || "http://localhost:3000";
89

910
server.use(cors({ origin: corsAllowedOrigin }));
1011

11-
server.use(basePath, express.static(buildPath));
12+
server.use(
13+
basePath,
14+
expressStaticGzip(buildPath, {
15+
enableBrotli: true,
16+
orderPreference: ["br"],
17+
})
18+
);
1219

1320
server.get(`${basePath}/internal/isAlive`, (req, res) => {
1421
res.sendStatus(200);

vite.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import react from "@vitejs/plugin-react";
33
import { viteMockServe } from "vite-plugin-mock";
44
import { rollupImportMapPlugin } from "rollup-plugin-import-map";
55
import EnvironmentPlugin from "vite-plugin-environment";
6+
import viteCompression from "vite-plugin-compression";
67
import cssInjectedByJsPlugin from "vite-plugin-css-injected-by-js";
78
import { terser } from "rollup-plugin-terser";
89
import { resolve } from "path";
@@ -23,6 +24,12 @@ export default ({ command }) => ({
2324
EnvironmentPlugin({
2425
NODE_ENV: process.env.NODE_ENV || "development",
2526
}),
27+
viteCompression({
28+
algorithm: "gzip",
29+
}),
30+
viteCompression({
31+
algorithm: "brotliCompress",
32+
}),
2633
viteMockServe({
2734
mockPath: "mock",
2835
localEnabled: command === "serve",

0 commit comments

Comments
 (0)