-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Parametric compile options #12415
Comments
to avoid multiple options turning into possibly function, what about having compile(r)Options itself be a function. The tricky bit is filename here as thats currently part of options.
if it was |
or introduce a new dynamicCompile wrapper that calls compile after resolving the options to avoid the overloaded signature of compile |
We discussed both these things and came to the conclusion that function per option is the best solution:
|
Another possibility is that we don't change the // svelte.config.js
export default {
compilerOptions: ({ filename }) => ({
css: filename.includes('/og-cards/') ? 'injected' : 'external',
runes: filename.includes('/node_modules/') ? undefined : true
})
}; |
but then each tool would have to check if compilerOptions is a function and call it first before passing the output to svelte.compile. It would be a bit more convenient and reduce duplication if there was a way to just pass compilerOptions to svelte.compile and have that figure it out. Last idea to that i have is adding a edit: passing source/content to the dynamic function can help too if you want to inspect svelte:options to selectively enable custom element output for example. |
Recapping the various solutions and their pros and cons: Make each property a function// svelte.config.js
export default {
compilerOptions: {
css: ({ filename }) => filename.includes('/og-cards/') ? 'injected' : 'external',
runes: ({ filename }) => filename.includes('/node_modules/') ? undefined : true
}
}; Pros:
Cons:
Add
|
my goto example for dynamicCompileOptions is to compile web components based on the presence of the tag option. It also allows people to add their own frontmatter compileOptions or whatever. we have the code and the filename, the question is why shouldn't we pass the code? |
I see, thanks. If we do this, then the following tools need updates:
|
prettier plugin might need it too? tbh i'd still prefer if svelte itself took care or it instead of introducing the same/similar code in all of the above to make it work. |
As pointed out in my post above, tooling needs to be adjusted anyway, because of how tooling sometimes manipulates the options, so this argument doesn't really apply IMO. For example, v-p-s modifies options here, though it seems like it does not do that after invoking dynamic compile options. |
v-p-s is the exception here though as it needs to manage some options for better dev experience and builtin ssr/client support. it would only have to do sth like
and possibly deprecate its own dynamicCompileOptions option |
if we make this a svelte.config.js thing we would have to think about reviving sveltejs/rfcs#59 or at least distribute a type and |
Rich and Dominic also favor the How would a |
For svelte2tsx we gotta make a compromise - since everything has to be sync, we can only pass the unpreprocessed file. Should be fine in practise because a preprocessor influencing the code in such a way that it in turn influences the compiler options is probably vanishingly rare. sveltejs/svelte#12415
Describe the problem
It's often useful to have different compiler options for different files. For example, you might want to enforce that all your first-party components are in runes mode, while continuing to use non-runes components in
node_modules
, or you might want to programmatically define custom element names rather than manually specifying them with<svelte:options>
in each component.Today, this is possible using
dynamicCompileOptions
invite-plugin-svelte
, but it has drawbacks:vite-plugin-svelte
svelte-check
can't take advantage of itDescribe the proposed solution
For the options where it makes sense, allow functions to be specified instead of values:
Importance
nice to have
The text was updated successfully, but these errors were encountered: