Skip to content

Commit

Permalink
style: minify GraphQL Playground CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneylab committed Nov 7, 2024
1 parent 83ea56b commit 714f870
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 989 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ rusty-tags.vi
video.tape
*.profraw
sqlite.db*
/assets
1 change: 1 addition & 0 deletions .gitleaksignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deno.lock:generic-api-key:10
21 changes: 21 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"fmt": {
"include": ["./**/*.ts"],
"exclude": ["public/", "target/"]
},
"lint": {
"exclude": ["public/", "target/"],
"rules": {
"tags": ["recommended"]
}
},
"tasks": {
"fmt": "yamlfmt . && dprint fmt && deno fmt && cargo fmt",
"minify:css": "deno run --allow-env --allow-read --allow-net --allow-run --allow-write scripts/minify-css.ts"
},
"imports": {
"@/": "./",
"browserslist": "https://esm.sh/browserslist@4.24.2",
"lightningcss": "https://esm.sh/lightningcss-wasm@1.28.1"
}
}
12 changes: 12 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions gitleaks-report.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
473 changes: 1 addition & 472 deletions public/fonts/fonts.css

Large diffs are not rendered by default.

472 changes: 0 additions & 472 deletions public/fonts/fonts_original.css

This file was deleted.

46 changes: 1 addition & 45 deletions public/static/css/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions scripts/minify-css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import browserslist from "browserslist";
import init, { browserslistToTargets, transform } from "lightningcss";

await init();

const targets = browserslistToTargets(
browserslist(
"> 0.5%, last 2 versions, Firefox >= 102, Firefox ESR, not dead",
),
);

async function minifyStylesheet(path: string) {
try {
const inputPath = `./assets/${path}`;
const outputPath = `./public/${path}`;
const css = await Deno.readTextFile(inputPath);
const { code: outputCss } = transform({
filename: inputPath,
code: new TextEncoder().encode(css),
minify: true,
targets,
});

const decoder = new TextDecoder();
await Deno.writeTextFile(outputPath, `${decoder.decode(outputCss)}\n`);
} catch (error: unknown) {
console.error(
`Error building styles for path ${path}: ${error as string}`,
);
}
}

const cssFiles = ["fonts/fonts.css", "static/css/index.css"];

for await (const file of cssFiles) {
minifyStylesheet(file);
}

0 comments on commit 714f870

Please sign in to comment.