How does webpack-encore works with symfony 5?

I’m getting a bit mad dealing with webpack-encore in a symfony 5 project.
There is few things i just don’t understand. first of all here is my webpack.config.js :

const Encore = require('@symfony/webpack-encore');

// Manually configure the runtime environment if not already configured yet by the "encore" 
// It's useful when you use tools that rely on webpack.config.js file.
if (!Encore.isRuntimeEnvironmentConfigured()) {
   Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');

// directory where compiled assets will be stored
// public path used by the web server to access the output path
// only needed for CDN's or sub-directory deploy

 * Each entry will result in one JavaScript file (e.g. app.js)
 * and one CSS file (e.g. app.css) if your JavaScript imports CSS.
.addEntry('app', './assets/app.js')

// enables the Symfony UX Stimulus bridge (used in assets/bootstrap.js)

// When enabled, Webpack "splits" your files into smaller pieces for greater optimization.

// will require an extra script tag for runtime.js
// but, you probably want this, unless you're building a single-page app

 * Enable & configure other features below. For a full
 * list of features, see:
// enables hashed filenames (e.g. app.abc123.css)

.configureBabel((config) => {

// enables @babel/preset-env polyfills
.configureBabelPresetEnv((config) => {
    config.useBuiltIns = 'usage';
    config.corejs = 3;

// enables Sass/SCSS support

// uncomment if you use TypeScript

// uncomment if you use React

// uncomment to get integrity="..." attributes on your script & link tags
// requires WebpackEncoreBundle 1.4 or higher

// uncomment if you're having problems with a jQuery plugin

module.exports = Encore.getWebpackConfig();

The thing is when i use {{ asset(‘build/images/my-image.png’) }} in my template the file is not found though it is in assets/images/my-image.png

How should i access my image???
Why it is not in manifest.json ??
Why am i not having images in my public/build/ folder ?
What path should i be using to reference my image in app.css as a background-image for example ?

This thing is a nightmare to use & configure…..
Thanks in advance

1 thought on “How does webpack-encore works with symfony 5?”

Leave a Comment