-
-
Notifications
You must be signed in to change notification settings - Fork 114
rewrite asset urls in template to use vite asset hashes #114
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
Comments
3b also would probably work with Could I exclude an image with Is this a preprocessor or done with the existing plugin resolve mechanism? |
This is a good point, interoperability with vite-plugins and other svelte preprocessors should be a goal here
unfortunately i don't think there is asset_exclude in vite , only include https://vitejs.dev/config/#assetsinclude
hmm, not sure how plugin resolve could work here even if we resolved the asset, we could'nt recompile the svelte component after the fact. so it has to either import the final urls from elsewhere (3b) or have them injected at compile time (which would need to know the hash in advance during build) |
I just got I had to do a couple things. I had to import with a special Vite URL. I had the format parameter appended to each include the original format. I also had to create an The code looks like this:
I setup the |
Yeah I feel like integration with We could have it so that this integration is automatically enabled if an |
What would be the ideal syntax for imagetools integration in svelte be then? Would it be similar to Anyways, I don't think the change should be in |
Tested using svelte-preprocess-import-assets with SvelteKit today and everything seems to be working fine. It should work on a normal Vite project too as that preprocessor only transforms inline asset sources to JS imports, which had always worked before. Re I'm closing this issue for now. |
When using svelte-preprocess-import-assets as a preprocessor of @sveltejs/vite-plugin-svelte , I found that it will throw an exception in the SFC file with |
Describe the problem
when using
<img src="./foo.jpg">
in svelte component template, the image has to be put in publicDir and isn't hashed by vites asset pipeline.see this discussion in svelte discord: https://discord.com/channels/457912077277855764/819723698415599626/868424304042319892
Describe the proposed solution
build a preprocessor to do the following:
asset_include
a) figure out vite hash of the asset and put hashed url in src
b) add
import x from "<url>"
and rewrite src to<img src={x}>
( see https://github.com/bluwy/svelte-preprocess-import-assets)add an option to inject that preprocessor within vite-plugin-svelte (like the others it's already doing)
Note: 3b would have the advantage that we don't need to figure out asset hashes as vite is going to rewrite the import down the road.
Alternatives considered
api.sveltePreprocess
aswell 🤔Importance
nice to have
Additional Considerations (see Discussion)
The text was updated successfully, but these errors were encountered: