Minimally reproducible setup here: https://github.com/jamesopti/webpack_playground/tree/resolve_url_loader_issue
Im trying to use resolve-url-loader
to add a hashname to my scss url()
image paths, but I'm having a heck of a time getting it to work with webpack 4.
I have a bunch of images in /static/img/**
which are referenced in my SCSS like:
span.arrow {
background: url(/static/img/audiences.png);
}
Which is ending up in my css as exactly the same thing (resolve-url-loader isnt finding them)
When I run the following configuration through webpack, I see that resolve loader is finding the right url()
and its path, but debug mode is saying NOT FOUND.
resolve-url-loader: /static/img/audiences.png
/Users/usr1/webpack_playground/src
/Users/usr1/webpack_playground/static/img
NOT FOUND
Is there some output config thats not correct? I've tried various combinations of the settings to no avail:
loader: 'resolve-url-loader',
options: {
debug: true,
root: path.join(__dirname, './static/img'),
includeRoot: true,
absolute: true,
},
My end goal is for file-loader to transform them to the /dist hashed version:
span.arrow {
background: url(/static/img/audiences-dhsye47djs82kdhe6.png);
}
// Webpack rules config
rules: [
{
test: /\.(png|jpg|gif)$/,
include: [
path.resolve(__dirname, './static/img'),
],
use: {
loader: 'file-loader',
options: {
name: '[name]-[hash].[ext]',
},
},
},
{
test: /\.svg$/,
use: {
loader: 'svg-inline-loader',
options: {
name: '[name]-[hash].[ext]',
},
},
},
{ test: /\/src\/js\/(?:.*)\.css$/, use: [ { loader: 'style-loader' }, { loader: 'css-loader' } ] },
{
test: [/\.scss$/, /\.sass$/],
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
{
loader: 'resolve-url-loader',
options: {
debug: true,
root: './static/img',
includeRoot: true,
},
},
{
loader: 'sass-loader',
options: {
outputStyle: 'compressed',
sourceMap: true,
includePaths: [
'./src'
],
},
},
],
},
]