Giter Club home page Giter Club logo

Comments (11)

washaweb avatar washaweb commented on May 17, 2024 1

If you want to use svg files, you have to add a file-loader in your webpack.dev.js and webpack.prod.js config files (in rules[] ) :

...
{
    test: /\.svg$/, 
    loader: 'file-loader' 
}
...

from webpack-starter-basic.

washaweb avatar washaweb commented on May 17, 2024 1

;-)

from webpack-starter-basic.

lifenautjoe avatar lifenautjoe commented on May 17, 2024 1

Thanks for the help @washaweb ! And sorry I couldn't look into this everyone else, stressing out over deadlines currently.

Will incorporate the solution into the README.

from webpack-starter-basic.

UlpiusCode avatar UlpiusCode commented on May 17, 2024

can you help me?

from webpack-starter-basic.

UlpiusCode avatar UlpiusCode commented on May 17, 2024

@washaweb this boilerplate use url-loader to loading images, why for svg images i need to use file-loader?
can I add svg here: test: /\.(png|jpg|gif|svg)$/, and load with url-loader? or from file-loader is better?

from webpack-starter-basic.

chrisschaetzlein avatar chrisschaetzlein commented on May 17, 2024

How can I reference to the SVG file in the index.html after I added the loader to webpack's config files? <img src="<% require('.src/path/to/image.svg') %>"> doesn't seem to work - it outputs only an empty string.

from webpack-starter-basic.

washaweb avatar washaweb commented on May 17, 2024

@chrisschaetzlein either remove the '.' at the beginning of the SVG path or add a slash just after. You URL should look like this:

<%= require('./src/path/to/image.svg') %>
or:
<%= require('src/path/to/image.svg') %>

from webpack-starter-basic.

chrisschaetzlein avatar chrisschaetzlein commented on May 17, 2024

@washaweb That was a typo in my comment, sorry. I already had ./src/path/to/image.svg. Webpack seems to find the file, it's included in the console output. Doesn't output anything to index.html though.

from webpack-starter-basic.

washaweb avatar washaweb commented on May 17, 2024

@UlpiusCode You could do that (using url-loader for your svg images), but doing so, SVG code would be converted in a base64 encoded image.
That is not a really a good thing if you intend to later modify your SVG code with CSS or JavaScript interactions.

from webpack-starter-basic.

washaweb avatar washaweb commented on May 17, 2024

@chrisschaetzlein do you place this code in a <img src=""> tag ?

from webpack-starter-basic.

chrisschaetzlein avatar chrisschaetzlein commented on May 17, 2024

@washaweb jeez, I started the include in the .html file with <% require instead of <%= require... sorry! It works with the latter, obviously 🙄

from webpack-starter-basic.

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.