Giter VIP home page Giter VIP logo

Comments (10)

danielduan avatar danielduan commented on May 29, 2024 1

you can also use webpack resource queries to determine which loader option you want to use for a given file extension.

{
  test: /\.svg$/,
  oneOf: [
    {
      resourceQuery: /css/,
      use: "svg-url-loader",
    },
    {
      resourceQuery: /js/,
      use: {
        loader: "svg-url-loader",
        options: {
          noquotes: true
        }
      }
    },
  ],
},

to import in javascript
import logo from 'logo.svg?js'
to import for css (or compiled languages such as less and sass)
require('logo.svg?css')

from svg-url-loader.

QoVoQ avatar QoVoQ commented on May 29, 2024

Meet the same problem, looking for a solution.
While setting noquotes: true,
// woubld be invalid if bg.svg is tranformed into inline svg
.bg { background: url('~images/bg.svg') }

<img src="~images/bg.svg" // would be valid in this case

Otherwise, setting noquotes: false
// woubld be valid if bg.svg is tranformed into inline svg
.bg { background: url('~images/bg.svg') }

<img src="~images/bg.svg" // would be invalid in this case

from svg-url-loader.

bhovhannes avatar bhovhannes commented on May 29, 2024

Guys, you need to specify noquotes option in image case and do not specify it in css case.
You have to explicitly override loader options in order to achieve that.

But that way you'll have 2 separate images in your bundle. Perhaps it will be better to use url-loader in terms of smaller bundle size...

from svg-url-loader.

QoVoQ avatar QoVoQ commented on May 29, 2024

Thanks for your attention.@bhovhannes
So you suggest us use url-loader? But I don't want inline svg base64 encoded.

from svg-url-loader.

bhovhannes avatar bhovhannes commented on May 29, 2024

@QoVoQ in your example you've mentioned the same image - bg.svg used in 2 different ways. In that case url-loader will give you a smaller bundle size, because bg.svg will be included only once in the final bundle.
In order to use svg-url-loader, you should tell webpack to use noquotes parameter in one case and not to use in the other one. It is totally possible.

from svg-url-loader.

fringd avatar fringd commented on May 29, 2024

from svg-url-loader.

bhovhannes avatar bhovhannes commented on May 29, 2024

@fringd , you have to explicitly pass noquotes option every time for each img tag

from svg-url-loader.

fringd avatar fringd commented on May 29, 2024

from svg-url-loader.

bhovhannes avatar bhovhannes commented on May 29, 2024

from svg-url-loader.

fringd avatar fringd commented on May 29, 2024

from svg-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.