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

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

Open igordos opened this issue 4 years ago • 5 comments

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] %>
  <% } %>
<% } %>
  • Node.js version: 12.16.1
  • webpack version: 4.43.0
  • svg-sprite-loader version: 5.0.0
  • OS type & version: Windows 10

Can you update code for new version? Thank you.

igordos avatar Jun 10 '20 12:06 igordos

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() %>

sqal avatar Jun 22 '20 15:06 sqal

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 avatar Jul 08 '20 12:07 quasarchimaere

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

quasarchimaere avatar Jul 29 '20 11:07 quasarchimaere

@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)

rjeny avatar Aug 18 '20 11:08 rjeny

@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

quasarchimaere avatar Aug 19 '20 09:08 quasarchimaere