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.

SVG as background-url in SFC <style> tag

See original GitHub issue

Context

Having the same issue, but instead of using the svgs in a .css file, I’m using them in the style tag of .vue files. Any work around that’ll let me keep them in there?

_Originally posted by @shmarts in https://github.com/egoist/svg-to-vue-component/issues/18#issuecomment-503520585_

Explanation

This issue was closed due to hotfix pr (#50), however this specific case is still a problem.

If you have svg-to-vue-component installed then you are unable to use svgs within the <style> section of a Vue single file component.

I guess a workaround in the meantime is to just import a css/sass file with the background-image.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:8

github_iconTop GitHub Comments

1reaction
m8schmitcommented, Sep 10, 2019

Like @franciscolourenco said you juste have to put

  chainWebpack(config) {
    const FILE_RE = /\.(vue|js|ts|svg)$/

    config.module.rule('svg').issuer(file => !FILE_RE.test(file)).oneOf('svg')

    config.module
      .rule('svg-component')
      .test(/\.svg$/)
      .issuer(file => FILE_RE.test(file))
      .oneOf('ignore')
      .resourceQuery(/\?ignore/)
      .use('file-loader')
      .loader('file-loader')
      .end()
      .end()
      .oneOf('normal')
      .use('vue')
      .loader('vue-loader')
      .end()
      .use('svg-to-vue-component')
      .loader('svg-to-vue-component/loader')

  }

And your css gonna look like

background-image: url("~@/assets/my-svg.svg?ignore");
Read more comments on GitHub >

github_iconTop Results From Across the Web

vue cli 3 – use background image in style tag - Stack Overflow
I used vue cli 3 and tried url('~@/assets/image.svg') but that didn't work, I don't know why. – Lying_cat. Mar 19, 2019 at ...
Read more >
06: Using SVG - SVG as background-image - CSS-Tricks
SVG images can be used as background-image in CSS as well, just like PNG, JPG, or GIF. .element { background-image: url(/images/image.svg); }.
Read more >
How to add SVGs with CSS (background-image)
Let's look at how to add SVGs into the CSS property background-image and how the related background properties can transform the results.
Read more >
Ways to embed a Clickable SVG-Logo into Your Website
All you have to do is open the .svg logo in a text editor, and copy paste the code. In the foreignObject, we...
Read more >
Inlining SVG background images in CSS with custom properties
myComponent { background-image: url('data:image/svg+xml;utf8,<svg> . ... Tagged with tinylesson frontend development css svgs background ...
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