svelte-retag icon indicating copy to clipboard operation
svelte-retag copied to clipboard

Support automatic definition via `<svelte:options customElement=... />` tag

Open patricknelson opened this issue 1 year ago • 1 comments
trafficstars

Describe the problem

Right now for a developer to define their custom elements, they must explicitly call svelteRetag(...) with their custom element configuration.

Relates to #13.

Describe the proposed solution

If the user is using Vite, we could define a custom plugin which will automatically parse and transform instances of <svelte:options customElement=... />, normalizing it down to remove the customElement definition (performed in pre processing) but retaining that information in scope for later processing. Then a second transformer running in post processing can inject the necessary JS to perform the initialization automatically in the emitted JS.

This could require AST (abstract syntax tree) processing. If so, consider using zimmerframe, since that will be what is used in Svelte 5, per https://github.com/micantoine/svelte-preprocess-cssmodules/pull/100#issue-1978258445.

Alternatives considered

None.

Importance

would make my life easier

patricknelson avatar Dec 13 '23 05:12 patricknelson

Tagging for v2 milestone for now, given it's more likely to be easier to implement once we are already stadardized on the customElement syntax.

patricknelson avatar Dec 13 '23 05:12 patricknelson