yarn add @symfony/webpack-encore --dev
// webpack.config.js
const Encore = require('@symfony/webpack-encore');
Encore
.setOutputPath('public/build/')
.setPublicPath('/build')
.addEntry('app', './assets/js/app.js')
.enableSingleRuntimeChunk()
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
.enableVersioning(Encore.isProduction())
;
module.exports = Encore.getWebpackConfig();
<!DOCTYPE html>
<html>
<head>
{# CSS assets #}
{% block stylesheets %}
{{ encore_entry_link_tags('app') }}
{% endblock %}
</head>
<body>
{# JavaScript assets #}
{% block javascripts %}
{{ encore_entry_script_tags('app') }}
{% endblock %}
</body>
</html>
yarn encore dev
yarn encore production
Your assets will be compiled and stored in the public/build directory. You can now easily manage and optimize your frontend assets using Webpack Encore in your Symfony project.