Giter VIP home page Giter VIP logo

Comments (7)

julienevano avatar julienevano commented on May 31, 2024 23

@romulof It is probably encoding the path instead of the url because you have 2 loaders for the same file:

  • the first loader (url) is encoding the image and returns a path to the encoded image
  • the second loader (file) is encoding path to the encoded image

The solution is to use a single loader, similar to:

{
  test: /\.(png|svg)$/,
  loader: 'url',
  query: {
    limit: 10000,
    name: 'assets/images/[name]-[sha512:hash:base64:7].[ext]'
  }
}

from url-loader.

romulof avatar romulof commented on May 31, 2024 19

Oh, I just read the code!

url-loader already uses file-loader as fallback.

from url-loader.

olistik avatar olistik commented on May 31, 2024 6

I guess the problem lies in the documentation, because if I read:

The url-loader works like the file-loader, but can return a DataURL if the file is smaller than a byte limit.

https://webpack.js.org/loaders/url-loader/#usage

and even if I read about the limit parameter later on:

If the file is greater than the limit (in bytes) the file-loader is used and all query parameters are passed to it.

I'm still not fully aware that I need to remove file-loader and that I can pass all of file-loader options within url-loader.

from url-loader.

romulof avatar romulof commented on May 31, 2024 2

If I force the loader, it works correclty:

const tickImg = require('!!url!../assets/tick.svg');
...

from url-loader.

romulof avatar romulof commented on May 31, 2024

Here's my webpack loaders configuration:

    {
      test: /\.(png|svg)$/,
      loader: 'url',
      query: {
        limit: 10000,
      },
    }, {
      test: /\.(png|jpg|svg)$/,
      loader: 'file',
      query: {
        name: 'assets/images/[name]-[sha512:hash:base64:7].[ext]',
      },
    }

from url-loader.

romulof avatar romulof commented on May 31, 2024

@julienevano, I'm not chaining the loaders. I have 2 distinct tests, one with url-loader only and another with file-loader only.

I'm not sure about how url-loader works when the limit query don't match. Let's say: if the file is bigger than limit the loader refuses the file and Webpack tries to find another loader for it?

How do you file-loader as fallback for url-loader?

from url-loader.

emkayy avatar emkayy commented on May 31, 2024

I have the same issue in SCSS files. When the file size exceeds the limit, module.exports = __webpack_public_path__ + "..."; gets base64 encoded as the file content!

Did you find any solution?

from url-loader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.