Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced express.static with expressStaticGzip #144

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"publish:cli": "bash scripts/publish-cli.sh"
},
"dependencies": {
"express-static-gzip": "^2.1.7",
"picocolors": "^1.0.0"
},
"devDependencies": {
Expand Down
11 changes: 7 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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() {
Expand Down Expand Up @@ -174,7 +177,7 @@ async function serveStatic(): Promise<RequestHandler> {
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();
Expand Down Expand Up @@ -368,7 +371,7 @@ export default {
bind,
listen,
build,
static: (options?: ServeStaticOptions) => {
static: (options?: ExpressStaticGzipOptions) => {
_State.staticOptions = options;
return stubMiddleware;
},
Expand Down