JavaScript Bundling — Vite, Webpack, esbuild
Also Known As
Vite
Webpack
esbuild
bundler
Laravel Mix
Laravel Vite
TL;DR
Bundlers combine JS modules into optimised files served by PHP — Vite for dev speed, Webpack for complex pipelines, esbuild for raw performance.
Explanation
PHP serves static assets (JS, CSS) either directly or via a bundler output. Vite (Rollup-based): instant dev server with HMR, fast production builds — recommended for new projects. Webpack: mature, rich plugin ecosystem, complex config — used in Laravel Mix. esbuild: Go-based, 10-100x faster than Webpack, minimal config. Laravel Vite plugin: integrates Vite with PHP's asset manifests. Bun: JS runtime + bundler. All output a manifest.json (or similar) mapping source files to hashed production filenames PHP uses.
Common Misconception
✗ PHP can serve unbundled JavaScript module files directly in production — browsers require many HTTP/2 requests for unbundled ES modules; a bundler reduces this to a few optimised files with tree-shaking and minification.
Why It Matters
PHP projects using modern JavaScript need a bundler to produce optimised assets — understanding Vite's asset manifest lets PHP correctly reference hashed filenames for cache-busting.
Common Mistakes
- Serving unbundled node_modules in production
- Not using the asset manifest for PHP template references
- Committing dist/ folder to git instead of building in CI
Code Examples
✗ Vulnerable
<!-- Referencing src file directly — no cache busting, no minification: -->
<script src="/resources/js/app.js"></script>
✓ Fixed
<!-- Vite manifest.json: {"resources/js/app.js": {"file": "assets/app.Abc123.js"}} -->
<!-- PHP reads manifest for hashed filename: -->
<?php
$manifest = json_decode(file_get_contents(public_path('build/manifest.json')), true);
$appJs = $manifest['resources/js/app.js']['file'];
?>
<script src="/build/<?= $appJs ?>" type="module"></script>
<!-- Or use Laravel's @vite('resources/js/app.js') directive -->
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
17 Mar 2026
Edited
22 Mar 2026
Views
29
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 2
Amazonbot 1
Amazonbot 9
Perplexity 5
SEMrush 3
Unknown AI 2
Google 2
Ahrefs 2
Majestic 1
Also referenced
How they use it
crawler 23
crawler_json 1
Related categories
⚡
DEV INTEL
Tools & Severity
🟡 Medium
⚙ Fix effort: Medium
⚡ Quick Fix
Use Laravel's @vite() directive or read the Vite manifest.json in PHP to reference correctly hashed asset filenames
📦 Applies To
javascript ES2015
web
laravel
🔍 Detection Hints
PHP templates hardcoding JS filenames without reading asset manifest; node_modules referenced directly in production HTML
Auto-detectable:
✗ No
lighthouse
webpack-bundle-analyzer
⚠ Related Problems
🤖 AI Agent
Confidence: Low
False Positives: Medium
✗ Manual fix
Fix: Medium
Context: File