svg-sprite-loader icon indicating copy to clipboard operation
svg-sprite-loader copied to clipboard

Deploying in prod with svg-sprite-loader

Open gooduserman opened this issue 7 years ago • 5 comments

I use svg-sprite-loader (last version) in a react app with extrac: true option.

The process build generates the files excactly where I want it. Similar like this: https://github.com/doug2k1/react-svg-icon

My problem is that altough in dev more, the full svg is included by the default in the body of the app, when used in prod the svg is not there, so usting svg tags referencing each id would not work.

Question: is there a way that the loader will add js script to insert the svg in the body, or should I do it by my self?

gooduserman avatar Sep 19 '18 10:09 gooduserman

Not sure that I understand you problem, I've launched your demo like so NODE_ENV=production webpack-dev-server -p and all icons are rendered correctly. image

kisenka avatar Sep 19 '18 10:09 kisenka

True. in dev mode it works great: it shows up in my dom. My problem is when I build for prod it and extracted as a file, there is no reference in dom about it. Do i have to put it myself?

gooduserman avatar Sep 19 '18 12:09 gooduserman

I see that you use prebuilt svg sprite - icons.svg. This loader was made to generate sprites dynamically from single SVG import (e.g. import './img.svg'). I don't know why it works in your case, but it shouldn't :)

kisenka avatar Sep 19 '18 13:09 kisenka

I saw that, but it was also good for injecting into the dom the svg :)

gooduserman avatar Sep 20 '18 04:09 gooduserman

Damn, that post pushed me in the wrong direction.

Just to confirm: https://www.webdevdrops.com/build-an-svg-icon-component-with-react-de9db211ebd6/ This is not how you are supposed to use svg-sprite loader right?

ghost avatar Feb 21 '19 11:02 ghost