jpkleemans / vite-svg-loader

Vite plugin to load SVG files as Vue components
MIT License
555 stars 59 forks source link

Modified isRootRef to use monorepo #53

Closed kyumoon closed 2 years ago

kyumoon commented 2 years ago

There is a problem using the plugin in a monorepo environment. svg files do not run on the plugin because the isRootRef value is true when referring to the svg file in a different directory.

If there is no issue, I hope the pull request will be accepted. thank you

error
index.45b22a28.js:4 DOMException: Failed to execute 'createElement' on 'Document': The tag name provided ('/assets/icn_arrow_up.a3b33b67.svg') is not a valid name.

project/pacakge-common/src/asset/svg/common.svg - is not coverted
project/pacakge-a/src/asset/svg/a.svg - is converted well
project/pacakge-a/index.html
jpkleemans commented 2 years ago

Hi, thanks for your PR! I'm not sure about this solution. If you'd go back 2 folders, for example, it still won't work.

How do you access the svg icons? Something like ../../package-common/src/asset/svg/common.svg? In that case, we could maybe add a rule when the path starts with ../ then it should not be treated as 'root' url.

kyumoon commented 2 years ago

Hi, you are right. if i use ../../. it's not working still. my PR only works if it starts with ../ i use allias common it works like ../ ex) common/assets/svg/icn_map.svg change to /Users/shane/Desktop/git/project/package-common/src/assets/svg/icn_map.svg

in my case:

root: /Users/shane/Desktop/git/project/package-a 
id: /Users/shane/Desktop/git/project/package-common/src/assets/svg/icn_map.svg

Actually, I don't know why you check isRootRef and I want you to remove it if possible. In the case of vue-svg-loader, similar conditions do not exist.

jpkleemans commented 2 years ago

You're right, I've removed the check and added a better solution in v3.4.0

jpkleemans commented 2 years ago

Thanks for your help!