How to fix webpack resolve-url-loader not working?
15:27 17 Jun 2019

Resolve-url-loader is not resolving images/fonts in my css files. My folder structure is like this:

src 
   public
      images
           -banner-bg.jpg
      stylesheets
         css
           -basic.css with background: url(../../images/banner-bg.jpg)
         scss
           -main.scss with @import "../css/basic.css";

The output folders:

dist
  public
     images
           -banner-bg.jpg
     stylesheets
           -main-output.css

The images & fonts diplay ok in dev server and are correctly copied in production. The main-output.css - when examined - shows

background:url(public/images/banner-bg.jpg

instead of the expected

background:url(../images/banner-bg.jpg)

And the browser console shows the error:

GET file:///home/ustrd/Documents/myproject12/dist/ public/stylesheets/public/images/ banner-bg.jpg net::ERR_FILE_NOT_FOUND

plugins: [
   new MiniCssExtractPlugin({
     filename: path.join("public", "stylesheets", "[name].css")
   })
 ],
 module: {
   rules: [
     {
       test: /\.(css|scss)$/,
       use: [
         MiniCssExtractPlugin.loader, 
         {
           loader: "css-loader",
           options: {
             sourceMap: true,
             importLoaders: 2
           }
         },
         {
           loader: "postcss-loader",
           options: {
             ident: "postcss",
             plugins: () => [new PostcssPresetEnv()]
           }
         },
         {
           loader: "resolve-url-loader",
           options: { sourceMap: true }
         },
         { loader: "sass-loader", options: { sourceMap: true } } 
       ]
     },

Any ideas how to fix that?

webpack path resolution resolve-url-loader