Symfony Webpack Encore Bundle
Twig integration that connects Webpack Encore's built assets to Symfony templates.
Repository Health
Technical Analysis
The Webpack Encore Bundle is the Symfony-side integration layer for Webpack Encore, Symfony’s frontend asset-building tool. It reads the entrypoints.json manifest that Encore generates during a build and exposes Twig functions (encore_entry_script_tags(), encore_entry_css_tags(), encore_entry_link_tags()) that render the correct <script>/<link> tags for a given entrypoint, including all its split chunks.
Beyond basic asset rendering, the bundle adds cache warming for the entrypoints manifest, integration with Symfony’s WebLink component for HTTP/2 resource preloading, and configuration for handling multiple Encore builds within a single Symfony project.
What You Get
- Twig functions to render script/style tags for a given Encore entrypoint, including split chunks
- Automatic parsing of Encore’s
entrypoints.jsonbuild manifest - Cache warming for the entrypoints manifest to avoid runtime file I/O in production
- HTTP/2 preload integration via Symfony’s WebLink component
- Support for multiple Encore builds (e.g. separate admin/frontend bundles) in one Symfony app
- Configuration for CDN/public-path prefixing of generated asset URLs
Common Use Cases
- Rendering the correct JS/CSS tags for a Webpack Encore entrypoint in a Symfony Twig layout
- Preloading critical assets via HTTP/2 push hints generated from the entrypoints manifest
- Running multiple independent Encore builds (e.g. one per Symfony bundle or admin area) in the same project
- Warming the asset manifest cache during deployment so first-request latency doesn’t include manifest parsing
- Serving Encore-built assets from a CDN by configuring a public-path prefix
Under The Hood
Architecture WebpackEncoreBundle.php is a standard Symfony bundle entry point wiring the bundle’s services into the DI container via DependencyInjection/. Asset/ contains the entrypoint-lookup and manifest-parsing classes that read Encore’s entrypoints.json, Twig/ exposes the encore_entry_*_tags() functions consumed by templates, CacheWarmer/ implements Symfony’s CacheWarmerInterface to pre-parse manifests during cache:warmup, and EventListener/ hooks WebLink preload header emission into the response lifecycle. Tech Stack Requires PHP 8.1+ and Symfony 5.4 through 8.0 components (asset, config, dependency-injection, http-kernel); dev dependencies pull in framework-bundle, twig-bundle, and web-link for integration testing across the full request/response/template cycle. Code Quality Static analysis is enforced via both PHPStan (with a baseline file for pre-existing findings) and Psalm, alongside PHPUnit tests in tests/; 55 contributors maintain it under the Symfony org’s shared CI and BC policy. API Design The Twig-function surface (encore_entry_script_tags, encore_entry_css_tags, encore_entry_link_tags) is deliberately small and declarative — template authors name an entrypoint and get back exactly the tags needed, with chunk-splitting, preloading, and multi-build complexity handled behind that one function call rather than exposed as configuration templates must reason about.
Used by 3 apps in this directory
BillaBear
Ecommerce · Invoicing Finance
Self-hostable subscription management and billing platform with Stripe integration, tax automation, configurable workflows, and Twig-based document generation.
Kimai
Invoicing Finance · Project Management
Professional open-source time tracking with invoicing, multi-user support, SAML/LDAP auth, and a full REST API—self-host it or use the cloud.
wallabag
Bookmarks Archiving
Self-hosted read-it-later app that saves clean, ad-free articles from any webpage for distraction-free reading across all your devices.