From be3f7f1d2f79883116ae401a659545f28ac30112 Mon Sep 17 00:00:00 2001 From: Jean Jesus <38874366+jeanjs@users.noreply.github.com> Date: Tue, 27 Aug 2024 20:20:05 -0300 Subject: [PATCH] chore: Add `express-static-gzip` dependency for improved static file serving --- package.json | 1 + src/main.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index ca4c85a..6c48b97 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "publish:cli": "bash scripts/publish-cli.sh" }, "dependencies": { + "express-static-gzip": "^2.1.7", "picocolors": "^1.0.0" }, "devDependencies": { diff --git a/src/main.ts b/src/main.ts index 04cffea..7533045 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,7 +5,10 @@ import http from "http"; import https from "https"; import path from "path"; import pc from "picocolors"; -import { ServeStaticOptions } from "serve-static"; +import expressStaticGzip, { + ExpressStaticGzipOptions, +} from "express-static-gzip"; + import type { HmrOptions, ViteDevServer } from "vite"; type ViteConfig = { @@ -23,7 +26,7 @@ enum Verbosity { const _State = { viteConfig: undefined as ViteConfig | undefined, - staticOptions: undefined as ServeStaticOptions | undefined, + staticOptions: undefined as ExpressStaticGzipOptions | undefined, }; function clearState() { @@ -174,7 +177,7 @@ async function serveStatic(): Promise { info(`${pc.green(`Serving static files from ${pc.gray(distPath)}`)}`); } - return express.static(distPath, { index: false, ..._State.staticOptions }); + return expressStaticGzip(distPath, { index: false, ..._State.staticOptions }); } const stubMiddleware: RequestHandler = (req, res, next) => next(); @@ -368,7 +371,7 @@ export default { bind, listen, build, - static: (options?: ServeStaticOptions) => { + static: (options?: ExpressStaticGzipOptions) => { _State.staticOptions = options; return stubMiddleware; },