Skip to content

Commit

Permalink
feat: add compression (#317)
Browse files Browse the repository at this point in the history
* feat: add compression

* pkg: lock compression
  • Loading branch information
danstarns committed May 20, 2024
1 parent 4da2f5c commit 7f789ac
Show file tree
Hide file tree
Showing 6 changed files with 4,448 additions and 9,637 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-landing-page.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ jobs:
cd ./docs/
pm2 restart graphql-debugger.com
cd ../apps/ui
DEMO_MODE=true pnpm build
NODE_ENV=production DEMO_MODE=true pnpm build
pm2 restart demo
5 changes: 3 additions & 2 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
"dev": "cross-env TRACE_SCHEMA=true TRACE_PRISMA=true TRACE_EXPRESS=true ts-node ./src/main.ts"
},
"dependencies": {
"@graphql-debugger/client": "workspace:^",
"@graphql-debugger/adapter-sqlite": "workspace:^",
"@graphql-debugger/client": "workspace:^",
"@graphql-debugger/graphql-schema": "workspace:^",
"@graphql-debugger/plugin-express": "workspace:^",
"@graphql-debugger/ui": "workspace:^",
"@graphql-debugger/utils": "workspace:^",
"cors": "2.8.5",
"express": "4.19.2"
"express": "4.19.2",
"express-static-gzip": "2.1.7"
},
"devDependencies": {
"@types/cors": "2.8.17",
Expand Down
8 changes: 7 additions & 1 deletion apps/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { graphqlDebugger } from "@graphql-debugger/plugin-express";

import cors from "cors";
import express, { Express } from "express";
import expressStaticGzip from "express-static-gzip";
import http from "http";
import path from "path";

Expand All @@ -30,7 +31,12 @@ export async function start({
client,
}),
);
app.use(express.static(path.join(__dirname, "../../ui/build")));
app.use(
"/",
expressStaticGzip(path.join(__dirname, "../../ui/build"), {
enableBrotli: true,
}),
);
app.use(express.static("public"));

const server = await app.listen(port);
Expand Down
3 changes: 2 additions & 1 deletion apps/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
},
"devDependencies": {
"@faker-js/faker": "8.4.1",
"@graphql-debugger/types": "workspace:^"
"@graphql-debugger/types": "workspace:^",
"compression-webpack-plugin": "11.1.0"
},
"engines": {
"node": ">=18",
Expand Down
8 changes: 8 additions & 0 deletions apps/ui/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
const CompressionPlugin = require("compression-webpack-plugin");

module.exports = {
mode: "none",
Expand Down Expand Up @@ -73,6 +74,13 @@ module.exports = {
favicon: "./public/favicon.svg",
}),
new NodePolyfillPlugin(),
...(process.env.NODE_ENV === "production"
? [
new CompressionPlugin({
deleteOriginalAssets: true,
}),
]
: []),
],
devServer: {
static: {
Expand Down
Loading

0 comments on commit 7f789ac

Please sign in to comment.