mrsum / webpack-svgstore-plugin

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

Used exact example in README and the svgxhr is doing something weird with the URL and I'm getting a 404 #142

Open jarodtaylor opened 7 years ago

jarodtaylor commented 7 years ago
import svgxhr from 'webpack-svgstore-plugin/src/helpers/svgxhr';

const __svg__ = {
  path: '../../assets/svg/**/*.svg',
  name: 'assets/svg/[hash].logos.svg'
};

svgxhr(__svg__);

I get this in my Chrome console:

VM21594:1 GET http://localhost:3000/http://localhost:3000/assets/svg/1494566510680.logos.svg 404 (Not Found)

If I console log svg I can see the filename: http://localhost:3000/assets/svg/1494566510680.logos.svg

and this filename works because when I view source I see the code.

What am I doing incorrectly?

designspin commented 7 years ago

I am experiencing an issue similar to this.

I am using browserSync with webpackDevMiddleware and a proxy.

smably commented 7 years ago

My first thought was that maybe this is related to publicPath, but I haven't yet had a chance to debug fully.

designspin commented 7 years ago

I fixed my issue by altering publicPath.

Vijayk93 commented 7 years ago

@designspin Can u tell me how did you fix this?I am also facing this issue

kazagkazag commented 6 years ago

Well, there is a workaround: you can write own loading function.

Just look at ./node_modules/webpack-svgstore-plugin/src/helpers/svgxhr.js, there is a code responsible for composing final URL:

if (typeof baseUrl === 'undefined') {
    if (typeof window.baseUrl !== 'undefined') {
      baseUrl = window.baseUrl;
    } else {
      baseUrl = window.location.protocol + '//' + window.location.hostname + (window.location.port ? ':' + window.location.port : '');
    }
  }

You can copy entire function, modify it and use instead of standard loader.

In my case, because of let replacement = expr.id.name + ' = { filename: ' + "__webpack_require__.p +" + '"' + data.fileName + '" }'; in svgstore.js webpack created filename with some addition (publicPath). But I use proxy (browsersync and http-proxy-middleware), so site is exposed on different url than publicPath (publicPath is absolute in my webpack config). Now while requesting sprite, loader try to compose final url from window.location parts and filename, which contains full path already.... So I created own loader. Now works fine, because I don't care about window.location.

CarpenterBug commented 6 years ago

I did a simpler workaround: https://github.com/mrsum/webpack-svgstore-plugin/issues/156. Hope it helps

zoellner commented 6 years ago

can confirm that this is an issue when using html-webpack-plugin with publicPath set. I'll see if I can put together a PR to fix

nadavsinai commented 5 years ago

hi, Just FYI, i've done this work and you can use my fork. npm i @algotec/webpack-svgstore-plugin#v5.1.2

I'm trying to get the owners to merge this for a while now...

https://github.com/Algotec/webpack-svgstore-plugin