Files
landing/build.mjs
mifi 02e4319459
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Let's try this...
2026-01-31 22:27:12 -03:00

49 lines
1.4 KiB
JavaScript

#!/usr/bin/env node
/**
* Build script: copies entire site/ to dist/, then inlines critical CSS in dist/index.html.
* Uses Critters (no headless browser) so the build runs in any environment.
* Dockerfile copies only dist/ — single source of truth for the built site.
*/
import Critters from "critters";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const ROOT = path.join(__dirname);
const SITE = path.join(ROOT, "site");
const DIST = path.join(ROOT, "dist");
async function main() {
// Copy entire site structure to dist
if (fs.existsSync(DIST)) {
fs.rmSync(DIST, { recursive: true });
}
fs.cpSync(SITE, DIST, { recursive: true });
console.log("✓ Copied site/ → dist/");
// Inline critical CSS in dist/index.html (Critters reads/writes relative to path)
const indexPath = path.join(DIST, "index.html");
let html = fs.readFileSync(indexPath, "utf8");
const critters = new Critters({
path: DIST,
preload: "default",
noscriptFallback: true,
pruneSource: false,
logLevel: "warn",
});
html = await critters.process(html);
fs.writeFileSync(indexPath, html, "utf8");
console.log("✓ Critical CSS inlined → dist/index.html");
console.log("Build complete. Output: dist/");
}
main().catch((err) => {
console.error(err);
process.exit(1);
});