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

Empty spritemap file #63

Open
Santana1053 opened this issue Dec 9, 2024 · 11 comments
Open

Empty spritemap file #63

Santana1053 opened this issue Dec 9, 2024 · 11 comments
Labels
bug Something isn't working need reproduction

Comments

@Santana1053
Copy link

After updating to v3.0.0, my spritemap file only contains an empty svg tag.

<svg xmlns="http://www.w3.org/2000/svg"/>

I assume this is somehow related to the svgo changes.

@Applelo
Copy link
Contributor

Applelo commented Dec 9, 2024

Weird because I didn't have any issue with my test demo folder. Even by fetching the package from npm. Can you provide a reproduction ?

@Applelo Applelo added bug Something isn't working need reproduction labels Dec 10, 2024
@haleyngonadi
Copy link

haleyngonadi commented Dec 12, 2024

@Santana1053 Did you figure this one out? I'm experiencing the same issue.

I figured this out. For me, I had to pass the glob as an array; so

VitePluginSvgSpritemap(['resources/icons/*.svg']) instead of VitePluginSvgSpritemap('resources/icons/*.svg')

@Applelo
Copy link
Contributor

Applelo commented Dec 12, 2024

@haleyngonadi Weird, I didn't touch this part + I tried with a glob string and didn't have any issue 🤔

@haleyngonadi
Copy link

@Applelo Maybe it is related to how our projects are setup? I downloaded the repo, and it worked fine as is, but not in my project, so weird!

@Applelo
Copy link
Contributor

Applelo commented Dec 12, 2024

@haleyngonadi Can you share a reproduction ? Or any clue (type of project...) to help me to reproduce the issue ?

@haleyngonadi
Copy link

@Applelo My project is a Laravel project. I think because my directories are deeply nested, the glob pattern was not working as expected!

@nakashu
Copy link

nakashu commented Dec 12, 2024

Had the same/similar issue.
Resolved it by using path.resolve

import path from "path";
VitePluginSvgSpritemap(path.resolve(__dirname, "./public/assets/*.svg"), {...}

Project is an almost clean install of react 19.0.0 using typescript.

Adding package.json, tsconfig and package.json for reference
tsconfig.json
package.json
vite.config.json - renamed to json, because github was unhappy with .ts :)

@Applelo
Copy link
Contributor

Applelo commented Dec 13, 2024

I tried with a vanilla react template from ViteJS with your vite config, no problem for me. Does this happen on dev, build or both ?
@nakashu What is your OS? Windows, MacOS or Linux ?

@nakashu
Copy link

nakashu commented Dec 13, 2024

@Applelo

Linux

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 24.04.1 LTS
Release:        24.04
Codename:       noble

node - v22.12.0
pnpm - 9.6.0

For me it's not really a problem. I tried the path solution it worked and I moved on.
I just seen the issue and tough, maybe it will help, to pinpoint the problem if it is real in react or something.

Will be working with it next days, so will try with different 'paths . vs ./ vs / ... etc etc.
Will let you know, if it work without the path.resolve

@Santana1053
Copy link
Author

I tried both path.resolve and wrapping the file string in an array but neither fix the issue for me on Windows.

@nakashu
Copy link

nakashu commented Dec 20, 2024

@Santana1053
If you are not using WSL (you definitely should), try changing the forward slashes / to backwards \ ones
Colleague of mine had problem with paths like this before he switched to WSL.

Windows does it differently :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working need reproduction
Projects
None yet
Development

No branches or pull requests

4 participants