egoist / svg-to-vue-component

Transform SVG files into Vue SFC (with hot reloading and SVGO support)
MIT License
235 stars 18 forks source link

The library is replacing more stuff than it should #18

Closed alexandernst closed 5 years ago

alexandernst commented 5 years ago

Overall I like the library, but there is one big bug that makes it unusable. It is replacing stuff that it shouldn't. For example, I have a flags library that will display country flags when I add the proper CSS classes to an element. But svg-to-vue-component is, somehow, replacing the background-image of that other library, and the result is:

vue_app

egoist commented 5 years ago

not sure how this happened, can you provide a complete example?

alexandernst commented 5 years ago

Sure! Here you go a completely new VUE project, with a simple Hello World component.

Just run npm install and npm run serve.

foobar.zip

The expected result is:

foobar

But instead, no flags are shown when your library is enabled in the vue.config.js.

egoist commented 5 years ago
// Use default rule for svg in css files
config.module.rule('svg')
  .issuer(file => file.endsWith('.css')

// Use our loader to handle svg imported by other files
config.module
  .rule('svg-component')
  .test(/\.svg$/)
  .issuer(file => !file.endsWith('.css'))
  .use('vue')
  .loader('vue-loader')
  .end()
  .use('svg-to-vue-component')
  .loader('svg-to-vue-component/loader')

This might work, can you give it a shot?

alexandernst commented 5 years ago

Yes, that seems to fix the issue! Thank you 👍

egoist commented 5 years ago

The doc has been updated: https://github.com/egoist/svg-to-vue-component#with-vue-cli

mrleblanc101 commented 5 years ago

How would i do this with Nuxt ?

shmarts commented 5 years ago

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?