Search code examples
imagesymfonywebpackassets

How to handle images with webpack encore & assets


so I seem to be a bit confused on how to work with images in webpack encore + assets.

I store all JS & CSS like this

/assets/js
/assets/css
...

With encore I can access them later from my /public/build folder - no issues there.

Now I want to store some images (e.g. file upload).

First idea was to store them inside a folder like /assets/images. But with the current settings & using assets I can only access files inside /public/build folder.

So I tried to use to copyFiles to copy everything from /assets/images to /public/build/images.

But this does not automatically copy my files (e.g. file upload to /assets/images/ does not copy it to /public/build - which is in order not accessible in my project). So I would need to run manually encore - which I don't want.


Second idea was to store the uploaded images directly inside /public/build/images but those files would be deleted when I run encore.

Next I disabled the webpack option cleanupOutputBeforeBuild, so images would not be deleted. But without this option the folder will be flooded by new JS & CSS Files everytime I run encore.


What do I need?

A solution to store my images either way in /assets folder & make them available for my project.

or

store the images directly in /public/build folder without encore deleting them nor flooding the folder with JS/CSS by disabling cleanupOutput Option.


Thanks in advance ~Syllz


Solution

  • Solution to my problem: Store the images into /public/images and not into the build folder - which will be deleted when running encore.