symfony/webpack-encore-bundle
Symfony bundle integrating Webpack Encore into your app. Adds asset building, versioning, and entrypoint management with simple Twig helpers for scripts/styles, plus sane defaults and easy configuration for modern JS/CSS workflows.
composer require symfony/webpack-encore-bundle. This auto-registers the bundle and installs webpack-encore dependencies (if using symfony/webpack-encore directly, also install yarn/npm).webpack.config.js (generated in assets/ by default). Define entrypoints (e.g., app, admin) and configure loaders, CSS preprocessors, etc.{{ encore_entry_link_tags('app') }}
{{ encore_entry_script_tags('app') }}
This automatically loads versioned CSS/JS from public/build/.yarn encore dev --watch
# or
symfony server:run --web-dir=public
The built-in dev server (via encore dev-server) provides hot module replacement (HMR) when running separately.admin.js, checkout.js) to enable efficient code splitting.import() in JS for lazy-loaded features (e.g., modals, charts), leveraging Webpack’s code splitting without manual chunk naming.Encore.isProduction() to conditionally enable minification, sourcemaps, or CDN paths in webpack.config.js.Encore.copyFiles() for optimized output (e.g., from: './assets/images', to: 'images/[path][name].[hash:8].[ext]').encore_entry_script_tags()/encore_entry_link_tags() with custom attributes (e.g., integrity, nonce) using the encore_entry_script_tags('app', { attrs: {'data-turbo-track': 'reload'}}) API.Cache-Control headers are disabled for /build/manifest.json—otherwise, asset requests may use stale filenames.entrypoints.json: In prod, always run yarn encore production before deploying; missing manifest causes UnexpectedValueException. Add it to CI build steps.encore dev-server uses port 8080. If blocked, configure via --port=9000 and update Encore.setOutputPath('public/build/') consistently.debug: true in config/packages/webpack_encore.yaml to print raw manifest paths—useful when entries fail to load silently.encore dev-server, configure devServer.proxy in webpack.config.js to avoid CORS issues (e.g., proxy /api/* to http://127.0.0.1:8000).Encore.configureBabel() or Encore.addLoader() to avoid overriding built-in behavior (e.g., polyfills for legacy browsers via @babel/preset-env).How can I help you explore Laravel packages today?