JetBrains / svg-sprite-loader

Webpack loader for creating SVG sprites.
MIT License
2.02k stars 270 forks source link

Example interop-with-html-webpack-plugin not working with html-webpack-plugin v4.3.0 #406

Open igordos opened 4 years ago

igordos commented 4 years ago

Code in template.ejs not working with html-webpack-plugin v4.3.0, but working with v3.2.0.

<% if (htmlWebpackPlugin.files.sprites) { %>
  <% for (var spriteFileName in htmlWebpackPlugin.files.sprites) { %>
    <%= htmlWebpackPlugin.files.sprites[spriteFileName] %>
  <% } %>
<% } %>

Can you update code for new version? Thank you.

sqal commented 4 years ago

Yeah, I ran into the same issue. As a workaround you can use this snippet to inject your SVGs instead of the old one:

<%= compilation.assets["sprite.svg"].source() %>

quasarchimaere commented 4 years ago

I am currently also running into this issue, however the approach of @sqal does not work for me since my sprite contains a contenthash (or i am missing some webpack.conf parameters), can someone help me out here?

quasarchimaere commented 4 years ago

I am currently also running into this issue, however the approach of @sqal does not work for me since my sprite contains a contenthash (or i am missing some webpack.conf parameters), can someone help me out here?

i am still searching for a working solution for this issue, is there a new way to do this now? @kisenka

rjeny commented 4 years ago

@quasarchimaere as I see your config, you set plainSprite: true in SpriteLoaderPlugin, so you will only have sprite.svg and code below will work.

But if it`s not a truth, ask yourself a question: you want to hash objets, that you want to be inlined. For what?)

p.s. Sorry if i wrong at all, I am just trying to help)

quasarchimaere commented 4 years ago

@rjeny i will try the approach you suggested and will get back to you on that, i see your point, inlining the sprite makes the hash useless. I think inlining would just be a workaround for me anyway, what i actually would have liked to achieve is to include (and preload) the hashed spritesheet in the template/index.html -> similar to the js and css resources in our project.

To clarify, this issue that we are having is not that the sprite doesnt work to begin with (svg icons are visible on our spa) however, the network traffic and visible delay, shows that the sprite is (re)fetched on each page change, which isnt really ideal imho