Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import of SVG-file fails with extraction (returns undefined) #106

Closed
wanecek opened this issue May 8, 2017 · 16 comments
Closed

Import of SVG-file fails with extraction (returns undefined) #106

wanecek opened this issue May 8, 2017 · 16 comments

Comments

@wanecek
Copy link
Contributor

wanecek commented May 8, 2017

With my current build-process, the import of an SVG-file returns undefined when extraction is turned on. with { extract: off } it returns an object as expected per documentation.

I have created a reduced test-case, which I will hope assist the debugging process.

Details of my setup:

  • Windows 10
  • Node v. 7.2.1
    See package.json for further details.

To Reproduce:

  • Download the test-case and install dependencies.
  • Start up the project with npm start. This should launch your web-browser at http://localhost:3000.
  • Open the console, and see that undefined is logged by Shell.vue:12, which attempts to log the import of ./assets/arrow.svg.
  • In build/webpack.base.conf.js:59, set extract: true and run the build process again.
kisenka added a commit that referenced this issue May 8, 2017
@kisenka
Copy link
Contributor

kisenka commented May 8, 2017

I found 3 issues:

  1. svg-sprite-loader in extract mode sometimes return wrong symbol url. It was fixed in svg-sprite-loader@2.1.0-1 (beta).
  2. Sprite loader plugin used twice - here and here.
  3. I am not sure, but looks like <svg><use xlink:href/></svg> embed method will not work with external sprite. I've replaced it with <img src="sprite.svg#id"> and it works:

image

Check my fork with updates - https://github.com/kisenka/svg-sprite-loader-test-case

@wanecek
Copy link
Contributor Author

wanecek commented May 8, 2017

Hi! Thank you very much for your reply and your thorough help!

I've taken note of the issues you found (sorry for the duplicate SpriteLoaderPlugin - my bad), and fixed them in recent commits. Furthermore, I've vastly simplified my test-case, e.g. by removing Vue from the build.

What I found was that using the beta-version removed the support for SpriteSymbol - instead a (system-relative) path is logged.

If you have more time to debug, I've pushed my changes to the same repo as before.

Thank you for your kind help and patience.

@kisenka
Copy link
Contributor

kisenka commented May 8, 2017

I think I understand what you want - svg image should goes to external sprite, but symbol (SpriteSymbol<id: string, viewBox: string, content: string>) should returns from import statement instead of symbol url. Am I right?

@wanecek
Copy link
Contributor Author

wanecek commented May 8, 2017

That is exactly what I want! :) Is that not the expected behavior?

@kisenka
Copy link
Contributor

kisenka commented May 8, 2017

Basically not, but I'll think about it. However it can be done via custom runtime generator, it was created for cases when you need some special stuff :) I've added example with extract mode in interop branch:

@wanecek
Copy link
Contributor Author

wanecek commented May 9, 2017

This is great, thank you! I'm very grateful of your commitment and help.

I'm still running into some issues with the sprite-loading though. More specifically, I cannot get the url to output the correct fragment-URL (e.g. sprite.svg#twitter-usage).

I've updated the test-case with the runtime generator, where it's evident that the url is undefined when using 2.0.5, and the system-relative path when using beta.

For 2.0.5, in the runtime-generator, symbol.request is C:\Users\NUC-10\Desktop\svg-sprite-loader-test-case\src\assets\arrow.svg and the spritePlaceholder is {{sprite-filename|C:\Users\NUC-10\Desktop\svg-sprite-loader-test-case\src\assets\arrow.svg}}

@kisenka
Copy link
Contributor

kisenka commented May 9, 2017

As I said here:

svg-sprite-loader in extract mode sometimes return wrong symbol url. It was fixed in svg-sprite-loader@2.1.0-1 (beta).

@wanecek
Copy link
Contributor Author

wanecek commented May 9, 2017

I've noted that. Unfortunately, this still returns the system-relative path instead of the build-relative path (i.e. C:\web\mainstream\src\assets\icons\logo.svg instead of sprite.svg#logo.)

If this is the expected behavior, it'd be lovely if you could give me a pointer for what to modify.
If not, and this is an issue, I can help resolve the issue if you give me pointers to as where to look :)

@kisenka
Copy link
Contributor

kisenka commented May 9, 2017

That strange. Could you push latest changes in your repo so I can check?

@WalterZou
Copy link

WalterZou commented May 9, 2017

@kisenka I have the same problem as @wanecek got:

I've noted that. Unfortunately, this still returns the system-relative path instead of the build-relative path (i.e. C:\web\mainstream\src\assets\icons\logo.svg instead of sprite.svg#logo.)
If this is the expected behavior, it'd be lovely if you could give me a pointer for what to modify.
If not, and this is an issue, I can help resolve the issue if you give me pointers to as where to look :)

When extract: false
Input:

import Logo from './assets/logo.svg'
console.log(Logo)

Output:

/D:\Code\DEV\svg-sprite-loader-test-case\src\assets\logo.svg

When extract: true
Input:

<img src="./logo.svg" alt="">

Output:

<img src="[object Object]" alt="">

This is my test case repo

@kisenka
Copy link
Contributor

kisenka commented May 9, 2017

@WalterZou could you please create repo with your setup?

@wanecek
Copy link
Contributor Author

wanecek commented May 9, 2017

@kisenka Commits are pushed to the repository

@kisenka
Copy link
Contributor

kisenka commented May 9, 2017

Got it, it's Windows path resolving issue. I will have access to Windows machine tomorrow, stay tuned!

@wanecek
Copy link
Contributor Author

wanecek commented May 9, 2017

Excellent @kisenka! Thank you very much for your help

kisenka added a commit that referenced this issue May 10, 2017
@kisenka
Copy link
Contributor

kisenka commented May 10, 2017

@wanecek please check svg-sprite-loader@2.1.0-3

@wanecek
Copy link
Contributor Author

wanecek commented May 11, 2017

Works like a charm! Thank you for all your help Kisenka.

@wanecek wanecek closed this as completed May 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants