Giter VIP home page Giter VIP logo

Comments (14)

jasongrout avatar jasongrout commented on May 31, 2024 3

For what it's worth, in JupyterLab we're using the url-loader with a mimetype specified, like this:

{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, use: 'url-loader?limit=10000&mimetype=image/svg+xml' }

(https://github.com/jupyterlab/jupyterlab/blob/bb7f8dabc2d4a927b325ca301ee02422522b7eeb/jupyterlab/staging/webpack.config.js#L134)

from url-loader.

iamstarkov avatar iamstarkov commented on May 31, 2024 1

@alexandrbig have two loader/ruler items with two different test regexps and different configuration

from url-loader.

sokra avatar sokra commented on May 31, 2024

Doesn't this work already?

from url-loader.

talves avatar talves commented on May 31, 2024

SVG needs xml data not base64. When I configure the svg as so, it fails:
{ test: /\.svg$/, loader: "url-loader?limit=50000&name=[path][name].[ext]&context=./src" }

Maybe I am doing something wrong.

from url-loader.

ColCh avatar ColCh commented on May 31, 2024

Use raw-loader for inline SVG!

From config:

// module.loaders =  ...
  {
      test: /\.(svg)$/,
      loader: 'raw-loader'
    }
// ...

Usage:

var image = require('../../images/icon.svg');
var Icon = React.createClass({
  render: function () {
    return (
        <div className="Icon" dangerouslySetInnerHTML={{__html: image}} />
      );
  }
});

... how we can optimize SVG on the fly?

from url-loader.

talves avatar talves commented on May 31, 2024

Yeah, after looking at what I was doing, I realized inline SVG should not be used from url-loader and handled it with file-loader instead. @ColCh your suggestion is noted, thanks.

from url-loader.

iamstarkov avatar iamstarkov commented on May 31, 2024

is it still the best solution?

from url-loader.

ColCh avatar ColCh commented on May 31, 2024

Idea of using multiple loaders for SVG is far mo-o-ore good solution than just raw-loader.

Sorry mate, I can't find issue thread discussion for this.

from url-loader.

iamstarkov avatar iamstarkov commented on May 31, 2024

prob you are talking about webpack/webpack#595

from url-loader.

NekR avatar NekR commented on May 31, 2024

This is what I get from url-loader for svg (decoded base64 string):

"module.exports = "<svg fill=\"#000000\" height=\"24\" viewBox=\"0 0 24 24\" width=\"24\" xmlns=\"http://www.w3.org/2000/svg\">\n    <path d=\"M0 0h24v24H0z\" fill=\"none\"/>\n    <path d=\"M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z\"/>\n</svg>""

Obviously this is wrong xml document.

from url-loader.

NekR avatar NekR commented on May 31, 2024

Oh, I got it, inline loader does not overrides default loader. It works, nevermind.

from url-loader.

alkema avatar alkema commented on May 31, 2024

@ColCh Great idea to use raw-loader for inline SVG. 👍 Works perfectly.

from url-loader.

ColCh avatar ColCh commented on May 31, 2024

@alkema pleased to help 😊

from url-loader.

alexandrbig avatar alexandrbig commented on May 31, 2024

Is it possible to load some svgs inline from one folder and all others like path only?
Please help.

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.