You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I might have svg files in src/img folder. But I might also have svg files in src/fonts. I wanna seperate them in build time. src/img svg files to dist/img, src/fonts to dist/fonts. Like this.
If i have folder structure like this "src/img/banners" and if i require these images from "src/img/banners", can i have dist folder structure like this "dist/img/banners"? Or just "dist/img"? Because i can have kind of folder structures in src. Like "src/fonts/OpenSans/..." or "src/img/banners/...". I wanna have dist folder like this "dist/fonts/OpenSans/..." or "dist/img/banners/...".
Common solution to hold same folder structure of asset resources in public path is using the property filename as the function.
Add to the module.rules in webpack config:
{test: /\.(png|jpg|jpeg|ico|svg|woff2)/,// filter for both images and fontstype: 'asset/resource',generator: {filename: (pathData)=>{const{ dir }=path.parse(pathData.filename);// get relative path started with `src/...`constoutputPath=dir.replace('src/','');// remove the source dir from pathreturnoutputPath+'/[name].[hash:8][ext]';// return output path with resource filename},},}
The output path dist/ will be have same directory structure as src/.
If you will use the responsive-loader then here is a bit complex. The option name is string. You can define here only some like [hash]-[width].[ext]. But exists the option outputPath that can be as function. Try to use this option like in example above.
Repository owner locked and limited conversation to collaborators on Apr 19, 2022
Activity
webdiscus commentedon Apr 18, 2022
hello @myasarbardaklar,
yes, it is possible.
Common solution to hold same folder structure of asset resources in public path is using the property
filenameas the function.Add to the module.rules in webpack config:
The output path
dist/will be have same directory structure assrc/.If you will use the
responsive-loaderthen here is a bit complex. The optionnameis string. You can define here only some like[hash]-[width].[ext]. But exists the optionoutputPaththat can be as function. Try to use this option like in example above.