Skip to content
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

Add preprocess option to svelte.compile #3690

Closed
vladshcherbin opened this issue Oct 12, 2019 · 2 comments
Closed

Add preprocess option to svelte.compile #3690

vladshcherbin opened this issue Oct 12, 2019 · 2 comments

Comments

@vladshcherbin
Copy link

Is your feature request related to a problem? Please describe.

I'm trying to use svelte/register in node.js for ssr, however components with scss or other preprocess features can't be used because preprocess is not called inside of register and result is an error.

It would be also useful for plain compile function, currently you have to pass your code twice, first to preprocess and then to compile. This addition will change this so you pass code only once to compile with an option.

Describe the solution you'd like
I'd like to have a preprocess option in compile function. This will also automatically add it to svelte/register.

Describe alternatives you've considered
I tried svelte/register and plain compile function, register gives error with preprocess features and compile gives errors with require. Bundling with rollup and then executing seems like the only alternative now.

How important is this feature to you?
I'm trying to make a plugin for generating ssr without the need to bundle app with rollup. Since it kinda works with bundling now, I can make it work and change when this feature is added. So the importance is low.

Additional context
Nope.

@Conduitry
Copy link
Member

svelte.compile is synchronous and svelte.preprocess is asynchronous (to allow for reading other files, or for async third-party libraries). require() is synchronous, and so the require hooks created by svelte/register also need to be synchronous. Adding a preprocess option to svelte.compile would cause it to become async (which we don't want to do), but also wouldn't work with svelte/register anyway. If you know that the particular preprocessing you're going to be doing is actually synchronous, your best bet is probably to write your own version of svelte/register that manually preprocesses the components before passing them on to the compiler - but this seems too niche and too restrictive for us to implement it in the official require hook.

@vladshcherbin
Copy link
Author

@Conduitry understandable, thank you for the detailed explanation 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants