-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
Automatically static asset handling #863
Comments
see enhanced image here https://kit.svelte.dev/docs/images |
Thank you.
But the main question was — why Svelte, which strives to adhere to web standards as much as possible, does not support a capability that has been in the web since its inception? |
enhanced:img provides the feature that you are asking for: automatic resolving of asset paths in the src attribute. There is also https://github.com/bluwy/svelte-preprocess-import-assets if you prefer not to use Maybe an argument could be made that vite-plugin-svelte should include this functionality directly, esp. since with vitePreprocess, asset urls in css will be resolved by vite and other frameworks also do it eg https://github.com/vitejs/vite-plugin-vue/blob/main/packages/plugin-vue/README.md#asset-url-handling But you have 2 existing options to get this feature working today by adding one extra preprocessor or plugin. |
There are several alternatives for the requested feature, this is not a blocker preventing the use of Svelte. If integrate svelte-preprocess-import-assets, Svelte will work exactly as needed.
Yes, this functionality exists in Vite, it's unclear why it's not present in Svelte directly. This is not a critical issue, but such behavior can be confusing. I like Svelte and would prefer that people learning it in the future encounter such issues as little as possible. If the Svelte team agree that this is a missing feature, then eventually this issue will be resolved. If this feature consciously not added, it would be good to have documentation about static resources in Svelte. The better understand why certain features are present or not in a framework, the more effectively you can use it. |
The best short term option is to document using svelte-preprocess-import-assets or enhanced:img as alternative to the common vite way of manually importing static assets https://vitejs.dev/guide/assets.html#importing-asset-as-url in https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md |
Update FAQ to include a section about inline asset URLs, as discussed in the following issue: sveltejs#863
Hello, I made a PR to update the docs: #898 , I'm semi-new to contributing so let me know if I did something wrong or if I did everything right, any feedback will be appreciated! |
Update FAQ to include a section about inline asset URLs, as discussed in the following issue: sveltejs#863
* Update faq.md Update FAQ to include a section about inline asset URLs, as discussed in the following issue: #863 * Update faq.md Fix some text not showing * Update faq.md Add an example to the inline assets section * Update faq.md Fix spacing between beginnings of parenthesis * docs(faq): update entry about relative asset urls --------- Co-authored-by: dominikg <[email protected]>
Describe the problem
In Svetle, basic and important functionality from Vite doesn't work — automatic handling of static resources from component folder only using HTML.
When initializing a new project in Svelte, there will be such lines:
It works, but I would like to have the ability to use notation like native HTML:
But this does not work.
In the documentation for Svelte and SvelteKit, I found information about this only in one place, in SvelteKit Images (I didn't find anything in the Svelte documentation on this topic). It says that when working with static resources, Svelte uses the Vite mechanism, which optimizes images: hashing in the name and
assetsInlineLimit
.But in Vite, both methods work: importing in JS and specifying the path directly in
src
, and both trigger the optimizations mentioned above.Documentation Vite Static Asset Handling about this:
Repository with Vite example, with
dist
folder code vite-test-staticDescribe the proposed solution
Is this missing of functionality or feature consciously not added?
If missing of functionality — it would be great to add a feature from Vite that allows working with static resources as in native HTML, without JavaScript.
If feature consciously not added — wonder why, especially considering that Svelte strives to adhere to web standards as much as possible. It would be good to add information to the Svelte documentation about working with static resources and why there is no possibility to work with them as in native HTML.
Alternatives considered
Using JS for add static resources:
This only way to added hashing in the name and use
assetsInlineLimit
,static
folder not did this.Importance
would make my life easier
The text was updated successfully, but these errors were encountered: