css-loader: v4 can't resolve absolute URLs

Creating a new bug report because #1136 was locked. Not trying to cause any problems. This is mainly for documentation for those of us who have been affected by this change, want to keep our deps up to date, but can’t easily remove absolute URLs from our CSS right now. I found a really simple workaround for this:

{
  test: /\.css$/,
  use: [
  {
    loader: 'css-loader',
    options: {
      url: (url, resourcePath) => {
        // Mimics v3 handling of absolute URLs.
        if (url.startsWith('/')) {
          return false
        }

        return true
      }
    }
  }
]
},

This seems to work exactly as v3 did.

@syberon @petertenhoor

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

Thanks! I already found this workaround a few days before. I use the same workaround but just little simplified the code:

            {
                test: /\.(css)$/,
                use: [
                    {
                        loader: 'css-loader',
                        options: {
                            url: url => !url.startsWith('/')
                        }
                    }
                ]
            },

As I written above you need to use in your case

Indeed, I’m gonna try it out next session - thanks!