svimg icon indicating copy to clipboard operation
svimg copied to clipboard

Consider providing as a Vite plugin

Open benmccann opened this issue 2 years ago • 3 comments

Vite is now the recommended way to build Svelte projects whether you're building a vanilla Svelte project or a SvelteKit project. The inputDir options duplicates Vite's publicDir option and the outputDir duplicates Vite's build.outDir. It'd be nice not to have to specify these again - especially since build.outDir is controlled by SvelteKit and is set to an obscure value that purposefully isn't documented to users. I wonder if this should be provided as a Vite plugin in addition to a Svelte preprocessor? A vite plugin can provide a preprocessor, so it should only require a minimal addition

https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#how-do-i-add-a-svelte-preprocessor-from-a-vite-plugin

benmccann avatar Aug 10 '22 13:08 benmccann

Actually, with Vite it's expected that you import your assets like so if you want plugins to operate on them or else they'll be left alone:

<script>
  import logo from '$lib/assets/logo.png';
</script>

<img alt="The project logo" src={logo} />

Users can use something like bluwy/svelte-preprocess-import-assets to do this automatically. The nice thing about this is that Vite will hash the file names so that they can be cached and the assets will go into the Vite image processing pipeline at that point so that plugins can operate on them. It probably makes sense to provide assets to Vite in this form (perhaps via bluwy/svelte-preprocess-import-assets or building that same logic into this plugin) and leverage the Vite pipeline to transform and emit assets.

benmccann avatar Aug 10 '22 13:08 benmccann

@benmccann How is svimg supposed to work together with Vite? Are you still actively using this or do you have another preferred approach?

kerns avatar Jan 02 '23 17:01 kerns

See here for my current preferred approach: https://github.com/sveltejs/kit/issues/241#issuecomment-1274046866

benmccann avatar Jan 02 '23 18:01 benmccann