build : minification JS avec esbuild 0.25.10 (14,0 -> 9,9 Ko br)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cette révision appartient à :
Théo GastineletClaude Opus 5.5 a révisé 2026-10-12 16:37:00 +02:00
1 Parent c914358ccd
révision 8097c5b0da
3 fichiers modifiés
+521 -3

Aucun fichier ne correspond à votre recherche

+12 -3
Voir le fichier
@@ -2,13 +2,14 @@
/**
* tools/build.js
*
* Build de production de gastinel.me — zéro dépendance (Node natif).
* Build de production de gastinel.me — Node natif + esbuild (minification JS ;
* `npm install` une fois).
*
* Source : index.html (on continue à l'éditer tel quel, CSS/JS inline).
* Sortie : dist/ (miroir de /srv/gastinel.me, prêt à déployer)
* - index.html HTML allégé (commentaires, indentation retirés)
* - assets/build/app.<hash>.css tous les <style> regroupés + minifiés
* - assets/build/app.<hash>.js le script principal, chargé en defer
* - assets/build/app.<hash>.js le script principal, minifié (esbuild), en defer
* - assets/build/<police>.<hash>.woff2 polices renommées (cache immutable)
* - assets/build/<section>.<hash>.html sections chargées à la demande (FRAGMENTS)
* - llms.txt, robots.txt, sitemap.xml, data/news.json
@@ -25,6 +26,14 @@ const path = require('path');
const zlib = require('zlib');
const crypto = require('crypto');
let esbuild;
try {
esbuild = require('esbuild');
} catch (e) {
console.error('esbuild manquant : lance `npm install` à la racine du projet.');
process.exit(1);
}
const ROOT = path.resolve(__dirname, '..');
const DIST = path.join(ROOT, 'dist');
const BUILD_DIR = 'assets/build';
@@ -121,7 +130,7 @@ function build() {
return '';
});
if (scripts.length !== 1) throw new Error(`1 script inline attendu, ${scripts.length} trouvé(s).`);
const js = scripts[0] + '\n';
const js = esbuild.transformSync(scripts[0], { minify: true, target: 'es2017' }).code;
const jsPath = emit(`${BUILD_DIR}/app.${hash(js)}.js`, js);
html = html.replace('<!--@@CSS@@-->',