In my project, I have some scss and with webpack I can build and bundle everything properly. In my scss file, I have some url to get some images. Such like that:
background-image: url(../img/example.svg),
This can be done thanks to these loaders in webpack: file-loader, sass-loader, css-loader and minicssextractplugin. Here is the working webpack config:
{
module: {
rules: [
{
test: /\.s?[ac]ss$/,
exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
},
{
loader: 'sass-loader',
}
],
},
{
test: /\.(svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader',
options: {
limit: 8192
},
}
]
},
]
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css'
})
]
}
My problem is that in the output folder (dist), I have all the images (see below the tree).
dist
|---- bundle.js
|---- bundle.css
|---- images
|---- example.svg
My idea is set the url like a fake url but I don't want sass to resolve the url and load the images. I just want to add the url as it is and don't want it to check the given path. Do you konw how if it is possible ?
dist/folder structure when using path into yourcssfiles. Try usingimg/example.svginstead. The bundle path will look atpath/to/project/dist/images/example.svg. - user7364588