Files
ink-website/astro.config.mjs
T
Your Name 9e6804c1ab
Deploy to GitHub Pages / build (push) Canceled after 0s
Deploy to GitHub Pages / deploy (push) Canceled after 0s
Initial commit
2026-10-11 18:09:42 +02:00

51 lines
1.9 KiB
JavaScript

import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';
import { readdirSync, readFileSync, rmSync, statSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { join } from 'node:path';
// Astro emits every imported screenshot at full size even when pages only use the optimised
// WebP variants. Drop originals nothing links to, so a deploy isn't ~17 MB heavier than needed.
function pruneUnusedOriginals() {
return {
name: 'prune-unused-originals',
hooks: {
'astro:build:done': ({ dir }) => {
const root = fileURLToPath(dir);
const files = [];
const walk = (d) => {
for (const n of readdirSync(d)) {
const p = join(d, n);
statSync(p).isDirectory() ? walk(p) : files.push(p);
}
};
walk(root);
const text = files
.filter((f) => /\.(html|css|js|xml|json|webmanifest)$/.test(f))
.map((f) => readFileSync(f, 'utf8'))
.join('\n');
for (const f of files) {
if (!/_astro[\\/][^\\/]+\.(png|jpe?g)$/.test(f)) continue;
const name = f.split(/[\\/]/).pop();
if (!text.includes(name)) rmSync(f);
}
},
},
};
}
// SITE_URL / BASE_PATH let CI set these without editing the file
// (e.g. a GitHub Pages project site: https://user.github.io + /ink-website).
export default defineConfig({
site: process.env.SITE_URL ?? 'https://ink.example',
base: process.env.BASE_PATH ?? '/',
output: 'static',
trailingSlash: 'always',
integrations: [sitemap(), pruneUnusedOriginals()],
build: { inlineStylesheets: 'auto' },
// lightningcss merges `backdrop-filter` + `-webkit-backdrop-filter` into the prefixed one only,
// which Chrome and Firefox ignore (no blur). esbuild leaves both declarations alone.
vite: { build: { cssMinify: 'esbuild' } },
devToolbar: { enabled: false },
});