Skip to content
This repository has been archived by the owner on Mar 18, 2023. It is now read-only.

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 this issue May 12, 2017 · 8 comments

Comments

@jarodtaylor
Copy link

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
Copy link

I am experiencing an issue similar to this.

I am using browserSync with webpackDevMiddleware and a proxy.

@smably
Copy link

smably commented Jun 7, 2017

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

@designspin
Copy link

I fixed my issue by altering publicPath.

@Vijayk93
Copy link

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

@kazagkazag
Copy link

kazagkazag commented Sep 29, 2017

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
Copy link

I did a simpler workaround: #156. Hope it helps

@zoellner
Copy link

zoellner commented Aug 3, 2018

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
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants