This document outlines the current implementation of the esbuild integration into the Eleventy project. The goal is to have an efficient JavaScript bundling and minification pipeline for both development and production environments.
The project now uses a single, powerful build-js.js script to handle all JavaScript bundling. This script is inspired by modern esbuild setups and provides a robust solution for both development and production.
- Single Build Script:
build-js.jsis the single source of truth for the JavaScript build process. - Environment-Specific Builds: The script differentiates between development (
--watchflag) and production (ELEVENTY_ENV=production) builds. - Bundle Analysis: In production builds, the script generates a metafile and provides a bundle analysis, giving insights into the composition of the final JavaScript bundle.
- Advanced Configuration: The script includes advanced esbuild options for tree-shaking, GSAP optimization, and more.
public/js/
main.js # Source JavaScript file
animations.js # Other JS modules
_site/js/
main.bundle.js # Bundled output for development and production
build-js.js # Standalone build script
.eleventy.js # Updated 11ty config
package.json # Updated with new scripts
- Run
npm start. - This command should trigger the
build-js.jsscript in watch mode (node build-js.js --watch). - esbuild will watch for changes in the JavaScript files and rebuild the bundle automatically.
- Run
npm run build. - This command should trigger the
build-js.jsscript to create a minified, production-ready bundle. - The script will also output a bundle analysis to the console.