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

histoire svelte doesn't include static files #334

Open
6 tasks done
MarcDAFrame opened this issue Oct 19, 2022 · 10 comments
Open
6 tasks done

histoire svelte doesn't include static files #334

MarcDAFrame opened this issue Oct 19, 2022 · 10 comments
Labels
bug Something isn't working svelte3

Comments

@MarcDAFrame
Copy link

MarcDAFrame commented Oct 19, 2022

Describe the bug

files in image tags can be referrenced like the following in svelte

<img src="/dir/file.png" />

Histoire doesn't return that file. However, it does return a file at /static/dir/file.png

Reproduction

create an image tag with a src="/dir/file.png" image the static folder, create a histoire story, import the svelte component with the image tag. The image does not load. now prepend the src path with static/ and the image wil load in Histoire

System Info

mac, chrome

Used Package Manager

npm

Validations

@MarcDAFrame MarcDAFrame added the to triage This issue needs to be triaged label Oct 19, 2022
@Akryum
Copy link
Member

Akryum commented Oct 19, 2022

Please provide a runnable reproduction, thanks!

@Akryum Akryum added need repro The issue needs a minimal reproduction to be fixed and removed to triage This issue needs to be triaged labels Oct 19, 2022
@MarcDAFrame
Copy link
Author

MarcDAFrame commented Oct 19, 2022

https://github.com/MarcDAFrame/HistoireStaticBugReproduction

  • notice how NoCases failed works in SvelteKit but doesn't work in Histoire
  • notice how NoCases Ready works in histoire but doesn't work in SvelteKit

this is because

  • failed: src="/res/nocases/failed.svg" (the proper SvelteKit syntax)
  • ready: src="/static/res/nocases/failed.svg"

@jim-fx
Copy link

jim-fx commented Dec 13, 2022

For me adding:

const config: UserConfig = {
  // This is for histoire
  publicDir: "static",
}

to my vite.config.ts fixed this problem, although sveltekit complains that this settings gets overwritten.

@Akryum
Copy link
Member

Akryum commented Dec 19, 2022

This should probably be fixed with #232

@benmccann
Copy link
Contributor

I would be surprised if #232 fixed this. https://github.com/histoire-dev/histoire/blob/main/packages/histoire-plugin-svelte/src/index.ts does not set publicDir. Histoire could load the svelte.config.js and read the files.assets config value with a default value of static to set this.

I'd also note however, that you rarely want to use the static directory. It's generally much better if you import your assets instead: https://kit.svelte.dev/docs/assets

@Akryum
Copy link
Member

Akryum commented Feb 5, 2023

@benmccann vite-plugin-sveltekit-setup should be loaded by the user vite config, shouldn't it?

@Akryum
Copy link
Member

Akryum commented Feb 5, 2023

Hmm looks like some necessary config is set in vite-plugin-sveltekit-compile, shouldn't it be in vite-plugin-sveltekit-setup?

@Akryum Akryum added bug Something isn't working svelte3 and removed need repro The issue needs a minimal reproduction to be fixed labels Feb 5, 2023
@benmccann
Copy link
Contributor

I didn't think publicDir should be part of vite-plugin-setup because if you include it in a project which has any public directory usage then we'll end up hijacking it. E.g. if Histoire has any files of its own in publicDir and we change it then we'll break things. I guess Histoire is a plugin so can't really expect users to put stuff there during installation though so on second thought perhaps you're right.

@benmccann
Copy link
Contributor

Although thinking about this more, if a user references static files in their components, I'm not sure how those components end up being distributable. If you import the assets they'll get included, but if you just reference them from static then I'm not sure they'll be in your package. So it seems to me that the fact that files in static don't work might be a feature more than a bug.

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

No branches or pull requests

4 participants