presspack
presspack copied to clipboard
Error with using background-image: url('some.jpg');
I got an error after adding a css rule with backgroung-image: url(some.jpg). After searching a bit I fix it by adding file-loader (yarn add file-loader --dev) and adding this to webpack.config.js rules: { test: /.(png|jpe?g|gif)$/i, use: [ { loader: 'file-loader', }, ], },
It's working but I don't know if it's a good solution.
It's a right approach. The options you have are either using the file-loader package or excluding the images folder entirely from the build.
Thanks for the lead, this will end up with a dysfunctional successful build containing url([object Module])
. Just turn off the esModule
flag. Now you can use your src as your root path.
{
test: /.(png|jpe?g|gif)$/i,
use: [
{
loader: 'file-loader',
options: { esModule: false },
},
],
},