Symfony Webpack Encore Bundle

Twig integration that connects Webpack Encore's built assets to Symfony templates.

Library
Composer
vv2.4.1
946stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
75/100Good
Development Activity76
Maintenance68
Community68
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
77/100Good
Architecture78
Code Quality82
Innovation68
Learning Curve78

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.json build 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search