symfony/webpack-encore-pack
Symfony integration for Laravel Mix/Encore workflows. Provides sensible defaults and tooling to compile and version JS/CSS assets with Webpack Encore, enabling modern frontend builds and easy asset management in Symfony apps.
Installation:
composer require symfony/webpack-encore-pack
This auto-configures Encore for Symfony projects, including Webpack 5+ and Babel integration.
First Use Case:
webpack.config.js in your project root (auto-generated by the pack).config/packages/encore.yaml:
encore:
entrypoints:
app: ['./assets/app.js']
yarn encore dev --watch
public/build/ (default).Key Files to Review:
webpack.config.js: Core Webpack config (entrypoints, loaders, plugins).assets/app.js: Default entry file (replace with your JS).config/packages/encore.yaml: Symfony-specific Encore settings.Asset Pipeline:
encore.input() in entry files:
// assets/app.js
import './styles/app.scss';
encore.addEntry() or import in JS/SCSS:
@import '~bootstrap/scss/bootstrap';
Symfony Integration:
{{ encore_entry_link_tags('app') }} in templates.yarn encore production # Minified, hashed filenames
yarn encore dev # Source maps, unminified
Modular Architecture:
encore:
entrypoints:
admin: ['./assets/admin.js']
frontend: ['./assets/frontend.js']
Shared Config:
webpack.config.js for project-specific rules:
Encore.enableSingleRuntimeChunk()
.enableSourceMaps(!Encore.isProduction())
.configureBabel(() => { /* Custom Babel config */ });
Caching Issues:
yarn encore production --watch --no-cache
php bin/console cache:clear
Webpack 5+ Quirks:
publicPath in webpack.config.js:
Encore.setPublicPath('/build');
app.abc123.js). Avoid hardcoding asset paths in templates.Symfony-Specific:
config/packages/dev/encore.yaml for production-like builds:
encore:
kernel_debug: false
{{ asset() }} for static files (not managed by Encore).Webpack Errors:
yarn encore dev --verbose for detailed logs.sass-loader for SCSS).Symfony Debugging:
{% if kernel.debug %}
{{ encore_entry_script_tags('app') }}
{% else %}
{{ encore_entry_script_tags('app', 'app-map') }}
{% endif %}
Custom Webpack Plugins:
webpack.config.js:
Encore.addPlugin(new CustomPlugin());
Babel Configuration:
Encore.configureBabel((config) => {
config.plugins.push('transform-class-properties');
});
PostCSS/Sass:
Encore.enablePostCssLoader()
.enableSassLoader(options => options.set('includePaths', ['node_modules']));
Environment Variables:
Encore.getContext() to access Symfony parameters:
const isDev = Encore.getContext().isProduction === false;
How can I help you explore Laravel packages today?