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.

How to import svg and fonts?

See original GitHub issue

Hi everyone! This isn’t a bug. But I’m a bit confused.

This is my project structure:

image

Font issue:

When I import a font with url in my sass file an error is shown in the build:

Module not found: Error: Can't resolve '../../fonts/BebasNeueBook.woff2'

Then in a .scss file (styles/base/reset.scss):

@font-face {
  font-family: 'BebasNeueBook';
  src: url('../../fonts/BebasNeueBook.woff2') format('woff2');
}

SVG issue:

I use the svg as follow:

<svg class="icon-menu">
    <use xlink:href="/icons/icons.svg#icon-menu"></use>
</svg>

But I can show this error in the dev tools console:

vue.esm.js?65d7:5819 GET http://localhost:9080/icons/icons.svg image

Tell me about your development environment.
  • Node version: 8.0.0
  • NPM version: 5.3.0
  • vue-cli version: 2.8.2
  • Operating System: MacOS 10.12.6

Thanks for any help you can give me! Regards!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

15reactions
hmaestacommented, Sep 21, 2018

For future Googlers, that’s what worked for me.

  • If use quote it doesn’t work
  • Fonts under /src/assets/fonts
  • Other formats were available (as SVG, for example), but when applied the font was ignored – so check every file format
@font-face {
    font-family: 'fontName';
    src:
       url(~@/assets/fonts/fontName.woff2) format('woff2'),
       url(~@/assets/fonts/fontName.woff) format('woff'),
       url(~@/assets/fonts/fontName.ttf) format('truetype');
    font-weight: normal;
    font-style: normal;
}
12reactions
SimulatedGREGcommented, Aug 31, 2017

@algil

For the font issue, you could try using the webpack alias with something like url(~@/assets/fonts/BebasNeueBook.woff2), where the @ provides you a reference to the src/ directory.

As for the SVG issue, you will not be able to use the xlink:href approach as vue-loader won’t treat that as a require statement. You could either alt for using a <img> tag, or place your icons within the static/ directory and access from there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Use Fonts in SVG - Vecta.io
The hard way. Locate the .ttf file for your font; Go to an online converter and convert it to base64; Embed into your...
Read more >
How do I use a custom font in an SVG image on my site?
That's an example for the following font: https://fonts.googleapis.com/css?family=Fredoka%20One Open visit the font page and copy everything ...
Read more >
SVG fonts - SVG: Scalable Vector Graphics - MDN Web Docs
There are some ingredients required for embedding a font in SVG. Let's show an example declaration (the one from the specification), and explain...
Read more >
Custom Font in svg - Stack Overflow
You can change fonts in svgs just as you do in css. <style> @font-face { font-family: font; src: url(font.woff); } svg{ font-family: font, ......
Read more >
Understanding and Using SVG Fonts in Photoshop and ...
SVG fonts are a new version of an Open Type format and contain things that fonts have never been able to contain, like...
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