Closed Hecatron closed 2 years ago
vite-plugin-svelte does have support for handling style tags with experimental.useVitePreprocess. That will use Vite's internal to process it, and you should turn off svelte-preprocess
then. And I think it'll work.
The reason aliases work in top-level styles
and not it svelte:head
is because:
svelte-preprocess
doesn't handle the alias by default, so the @import
is left as is..css
request, so Vite can process it (note is not the same as useVitePreprocess
, as this is processed after Svelte compiles, useVitePreprocess
work before compile)svelte:head
styles, it's not split into a separate .css
request, because it's embedded into the head
(it's compiled into JS)Plus, it's not conventional to put styles in svelte:head
, but I understand that it's a workaround to the Svelte issue you pointed (https://github.com/sveltejs/svelte-preprocess/pull/531)
If useVitePreprocess
work for you, I don't think there's anything else vite-plugin-svelte
can do. The core issue probably needs to be resolved to have a better experience overall.
Thanks very much that does seem to work with a normal vite site and is exactly what I was looking for With storybook from the looks of things I still need to use the svelte-preprocess method but that should hopefully go away once they move to version 7 Since I think the error I'm seeing with that it's being caused by the use of CommonJS for it's config files
The workaround I mentioned before I've put up here btw as a pull request
Describe the bug
Hi, One of the things I've noticed is that the alias's are not picked up for style tags inside svelte:head
This is something I've been using for storybook as any global styles inside svelte:head seem to be unloaded when switching between different components (which is useful)
As an example:
This works fine
This also works
This isn't picked up
I can work around this using svelte-preprocess
by passing in a special function into it's scss importer setting.
But I suspect it might be better if this was supported natively instead.
I wasn't sure if this should be raised here or in one of the rollup plugins since I'm not sure where it's actually evaluated
Any thoughts?
Reproduction
When prompted select svelte then svelte-ts
vite.config.ts
with svelte-preprocess disabled just to be sure that's not interfering
Logs
No response
System Info