Files

27 lines
940 B
JavaScript

/**
* Gzip script for ESP32 deployment.
* Compresses dist/index.html -> dist/index.html.gz
* Uses Node.js built-in zlib (no extra dependencies).
*/
import { readFileSync, writeFileSync } from 'fs';
import { gzipSync } from 'zlib';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const inputPath = resolve(__dirname, '..', 'dist', 'index.html');
const outputPath = resolve(__dirname, '..', 'dist', 'index.html.gz');
const input = readFileSync(inputPath);
const compressed = gzipSync(input, { level: 9 });
writeFileSync(outputPath, compressed);
const inputKB = (input.length / 1024).toFixed(1);
const outputKB = (compressed.length / 1024).toFixed(1);
const ratio = ((1 - compressed.length / input.length) * 100).toFixed(0);
console.log(`Gzip: ${inputKB} kB -> ${outputKB} kB (${ratio}% reduction)`);
console.log(`Output: dist/index.html.gz`);