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
Support emitting preprocessed .svelte files #475
Comments
Thank you, @dominikg! Since Vite plugins are becoming so valuable and useful as of late, it would be great if they could be used for For context here is my PR unocss/unocss#1725 for the temporary svelte preprocessor wrapper I had to write which inits UnoCSS and then imports the transformSvelteSFC method. It actually wasn't too difficult to write this wrapper, but in the long run I'd rather use the Vite plugin instead for a few reasons:
I don't have enough knowledge to give advice on how to accomplish the task proposed in this issue but I can help test things out as helpful. |
related work: https://github.com/sveltejs/vite-plugin-svelte/tree/preprocess-api contains an export for standalone preprocessors unsing vite config, these could be used to generate the preprocessed output without additional features in v-p-s. It may still be nicer to offer a way to do this as part of a vite build to be able to produce extra resources alongside, eg the aforementioned styles generated by unocss. |
Describe the problem
svelte-package currently does not read vite config at all and doesn't understand our
useVitePreprocess
option as a result.This can lead to a divergence in library projects that use vite plugins like unocss or windicss for styles which look just fine in the preview during
pnpm dev
, but preprocessed output isn't working and a companion global css file can't be created efficientlySee unocss/unocss#1725 for a draft of a custom preprocessor to solve it for unocss, but the problem is of a more general nature and we might want to offer tooling so that it can be solved with less effort.
Describe the proposed solution
1. idea by @bluwy: a new
?preprocess
directiveWhich allows svelte-package and friends to glob .svelte files and then call ssrLoadModule on them to get the preprocessed output of each one
2. a custom build option
add an option to output preprocessed .svelte files to a separate directory alongside compiled code via a rollup output hook
The output of
vite build
can then be used to get the preprocessed codeAlternatives considered
Somehow add a preprocessor to svelte.config.js that allows uses vite+svelte under the hood, kind of the inverse of the above, but this risks inception
Importance
nice to have
The text was updated successfully, but these errors were encountered: