I try to configure Webpack 5 such it keeps the assets folder structure for my images and fonts.
I have the following structure:
- /app
/assets
/images
/topic1
/topic2
/fonts
In my webpack config I have configured the Assets module like that:
{
test: /\.(png|svg|jpg|jpeg|gif|xml)$/i,
type: 'asset/resource'
}
...
same for Font files...
If I run the Webpack 5 build it copies the assets by default to my dist/
folder in a flat structure, e.g. images below the folder /topic1
are directly copied to dist/my-topic1-img.png
but actually I would like to have it here: dist/assets/images/topic1/my-topic1-img.png
.
How can I easily achieve this?
I have seen this doc link here: https://webpack.js.org/configuration/module/#rulegeneratorfilename. So I assume a solution could be to write some custom filename
function which would set dynamically depending on the file path a new filename including the path elements for each asset.
Does Webpack 5 support such a config out-of-the-box or do I really need to write some custom function for this?
Thanks for help and inputs.