mrsum / webpack-svgstore-plugin

Simple svg-sprite creating with webpack
https://www.npmjs.com/package/webpack-svgstore-plugin
200 stars 92 forks source link

Retrieve generated .svg file content in js #125

Open rlebosse opened 7 years ago

rlebosse commented 7 years ago

Instead of loading asynchronously the generated .svg file, is there a way to retrieve synchronously it's content in a js file in order to insert it in the webpage the way we want to ?

Something like this :

import svgStore from 'webpack-svgstore-plugin';

console.log(svgStore);
// <svg xmlns="http://www.w3.org/2000/svg" style="position:absolute; width: 0; height: 0"> ...

Thanks!

joaquimjmsilva commented 7 years ago

Hi, I had the same need, so I did like this: var __svg__ = { path: '../icons/*.svg', name: '[hash].icons.svg' }; // console.log(__svg__.filename); - Has the public path of the file, so you can use it for what you want. // For example: <svg> <use xlink:href="<%=__svg__.filename %>#icon-<name>" /> </svg>