presspack icon indicating copy to clipboard operation
presspack copied to clipboard

Error with using background-image: url('some.jpg');

Open teikirizi opened this issue 5 years ago • 2 comments

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.

teikirizi avatar Aug 13 '19 01:08 teikirizi

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.

Alina-chan avatar Dec 02 '19 15:12 Alina-chan

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 },
    },
  ],
},

onetdev avatar Jun 02 '20 21:06 onetdev