diff --git a/apps/client/package.json b/apps/client/package.json index 2c629a7e9..d836d5db6 100644 --- a/apps/client/package.json +++ b/apps/client/package.json @@ -4,7 +4,7 @@ "version": "0.95.0", "scripts": { "dev": "vite", - "build": "tsc && vite build && node scripts/compress-dist.mjs", + "build": "tsc && vite build", "lint": "eslint .", "preview": "vite preview", "format": "prettier --write \"src/**/*.tsx\" \"src/**/*.ts\"", diff --git a/apps/client/scripts/compress-dist.mjs b/apps/client/scripts/compress-dist.mjs deleted file mode 100644 index 09b941c95..000000000 --- a/apps/client/scripts/compress-dist.mjs +++ /dev/null @@ -1,48 +0,0 @@ -import { promises as fs } from "node:fs"; -import { join, extname } from "node:path"; -import { promisify } from "node:util"; -import zlib from "node:zlib"; - -const gzip = promisify(zlib.gzip); -const brotli = promisify(zlib.brotliCompress); - -const DIST = new URL("../dist", import.meta.url).pathname; -// index.html is rewritten by the server at boot, so html must not be precompressed -const COMPRESSIBLE = new Set([".js", ".css", ".svg", ".json", ".txt", ".map"]); -const MIN_SIZE = 1024; - -async function* walk(dir) { - for (const entry of await fs.readdir(dir, { withFileTypes: true })) { - const path = join(dir, entry.name); - if (entry.isDirectory()) yield* walk(path); - else yield path; - } -} - -const files = []; -for await (const file of walk(DIST)) { - if (!COMPRESSIBLE.has(extname(file))) continue; - const { size } = await fs.stat(file); - if (size >= MIN_SIZE) files.push(file); -} - -await Promise.all( - files.map(async (file) => { - const content = await fs.readFile(file); - const [gz, br] = await Promise.all([ - gzip(content, { level: 9 }), - brotli(content, { - params: { - [zlib.constants.BROTLI_PARAM_QUALITY]: 11, - [zlib.constants.BROTLI_PARAM_SIZE_HINT]: content.length, - }, - }), - ]); - await Promise.all([ - fs.writeFile(`${file}.gz`, gz), - fs.writeFile(`${file}.br`, br), - ]); - }), -); - -console.log(`precompressed ${files.length} assets (.gz/.br)`); diff --git a/apps/server/src/integrations/static/static.module.ts b/apps/server/src/integrations/static/static.module.ts index 4e5f9b486..5914a3e07 100644 --- a/apps/server/src/integrations/static/static.module.ts +++ b/apps/server/src/integrations/static/static.module.ts @@ -71,7 +71,6 @@ export class StaticModule implements OnModuleInit { await app.register(fastifyStatic, { root: clientDistPath, wildcard: false, - preCompressed: true, setHeaders: (reply: any, pathName: string) => { // Vite content-hashes everything under /assets, so they can be cached forever if (/[\\/]assets[\\/]/.test(pathName)) {