Skip to content

Instantly share code, notes, and snippets.

@Nooshu
Created February 20, 2026 13:29
Show Gist options
  • Select an option

  • Save Nooshu/a6299b047d6f88a586de9b126216b49e to your computer and use it in GitHub Desktop.

Select an option

Save Nooshu/a6299b047d6f88a586de9b126216b49e to your computer and use it in GitHub Desktop.
The build events file that I use with my 11ty build. It contains extensive logging that output to the Cloudflare pages build log.
import env from '../_data/env.js';
import { clearCssBuildCache } from '../_helpers/css-manipulation.js';
import { generatePreloadHeaders } from '../_helpers/header-generator.js';
import { compressHtmlFiles } from '../_helpers/html-compression.js';
import { compressJavaScriptFiles } from '../_helpers/js-compression.js';
import { minifyJavaScriptFiles } from '../_helpers/js-minify.js';
/**
* Register eleventy.before and eleventy.after handlers.
* Only registered when !env.isLocal (production/preview)
* @param {import("@11ty/eleventy").UserConfig} eleventyConfig
*/
export function registerBuildEvents(eleventyConfig) {
if (env.isLocal) {
return;
}
eleventyConfig.on('eleventy.before', () => {
clearCssBuildCache();
});
eleventyConfig.on('eleventy.after', async () => {
console.log('\n═══════════════════════════════════════════════════════════════════════════════');
console.log('🚀 PRODUCTION POSTBUILD PHASE: Beginning postbuild operations');
console.log('═══════════════════════════════════════════════════════════════════════════════\n');
generatePreloadHeaders();
await minifyJavaScriptFiles();
compressJavaScriptFiles();
compressHtmlFiles();
console.log('\n═══════════════════════════════════════════════════════════════════════════════');
console.log('✅ PRODUCTION POSTBUILD PHASE: All postbuild operations completed');
console.log('═══════════════════════════════════════════════════════════════════════════════\n');
console.log('🔧 Forcing cleanup of HTTP connections and timers...');
await new Promise(resolve => setTimeout(resolve, 100));
try {
const http = await import('http');
const https = await import('https');
if (http.globalAgent) {
http.globalAgent.destroy();
console.log('✅ Destroyed HTTP global agent');
}
if (https.globalAgent) {
https.globalAgent.destroy();
console.log('✅ Destroyed HTTPS global agent');
}
} catch (error) {
console.warn('⚠️ Could not destroy HTTP agents:', error.message);
}
await new Promise(resolve => setTimeout(resolve, 50));
console.log('✅ HTTP connection cleanup completed');
if (env.isProd) {
console.log('🏁 Production build complete - forcing process exit in 2 seconds...');
setTimeout(() => {
console.log('👋 Forcing clean exit now');
process.exit(0);
}, 2000);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment