question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

webpack url-loader seems not working when handling the images files imported using `url()` CSS function

See original GitHub issue

Current Behavior

I am using the NX with react, webpack used for building my app. But I found that the url-loader configured in @nrwl/react/plugin/webpack.js not working when images imported using url() CSS function.

But the assets imported by this seem handled by file-loader(i am not sure, just see them in dist), but the hash in the filename is greater than 7 digits, and it smaller than 10000bytes which should have been handled by url-loader.

BTW, the files imported in my .ts file handled by url-loader properly.

The url-loader config:

{
  "rules": [
    {
      "test": /\.(png|jpe?g|gif|webp)$/,
      "loader": require.resolve("url-loader"),
      "options": {
        "limit": 10000,
        "name": "[name].[hash:7].[ext]"
      }
    },
    {
      "test": /\.svg$/,
      "oneOf": [
        // If coming from JS/TS file, then transform into React component using SVGR.
        {
          "issuer": {
            "test": /\.[jt]sx?$/
          },
          "use": [
            "@svgr/webpack?-svgo,+titleProp,+ref![path]",
            {
              "loader": require.resolve("url-loader"),
              "options": {
                "limit": 10000,
                "name": "[name].[hash:7].[ext]",
                "esModule": false
              }
            }
          ]
        },
        // Fallback to plain URL loader.
        {
          "use": [
            {
              "loader": require.resolve("url-loader"),
              "options": {
                "limit": 10000,
                "name": "[name].[hash:7].[ext]"
              }
            }
          ]
        }
      ]
    }
  ]
}

Expected Behavior

These assets should handled by url-loader if the size is smaller than 10000 bytes, otherwise should be handled by file-loader which outputs the file, contain 7 digits hash in the file name.

Steps to Reproduce

You can add a background image in nx-emaples and run nx build --prod. You will see the result.

Failure Logs

Environment

nx : Not Found @nrwl/angular : 10.3.1-beta.1 @nrwl/cli : 10.3.1-beta.1 @nrwl/cypress : 10.3.1-beta.1 @nrwl/eslint-plugin-nx : Not Found @nrwl/express : Not Found @nrwl/jest : 10.3.1-beta.1 @nrwl/linter : 10.3.1-beta.1 @nrwl/nest : Not Found @nrwl/next : Not Found @nrwl/node : Not Found @nrwl/react : 10.3.1-beta.1 @nrwl/schematics : Not Found @nrwl/tao : 10.3.1-beta.1 @nrwl/web : 10.3.1-beta.1 @nrwl/workspace : 10.3.1-beta.1 typescript : 4.0.3

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
shahnawazcommented, Sep 24, 2021

Is there any update on this issue?

Unable to load fonts using url.

1reaction
patriknieburcommented, Apr 28, 2021

I moved my css imports from App.tsx to workspace.json’s styles, no more warnings.

Thanks, this helped my use case. Font icons referenced in the css file I was using did not load. I was importing styles from semantic-ui and adding it into the workspace.json project styles like this fixed my problem:

"styles": ["node_modules/semantic-ui-css/semantic.min.css"],
Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack url-loader or file-loader not working react app
For loading images using url-loader. If you notice inside config/webpack.config.js There is a module object which has rules object inside it ...
Read more >
url-loader | webpack - JS.ORG
A loader for webpack which transforms files into base64 URIs. Getting Started. To begin, you'll need to install url-loader : $ npm install...
Read more >
Handling Images - Medium
With Webpack, the image loading can be optimized using the url-loader that converts your images to base64 strings and inlines those within the...
Read more >
Loading Styles - SurviveJS
Webpack doesn't handle styling out of the box, and you will have to use loaders ... css-loader goes through possible @import and url()...
Read more >
webpack Tutorial: How to Set Up webpack 5 From Scratch
file -loader , raw-loader and url-loader are not necessary, you can use built in asset modules; Node polyfills are no longer available, so...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found