Skip to content

Break out individual compilers #1678

Open
@Rich-Harris

Description

@Rich-Harris

As frequenters of the Discord server will know, I'm become obsessed lately with the idea of compiling Svelte components to WebGL code (not for UI, but for building 3D/VR scenes — the sort of thing you'd traditionally use Three.js or A-Frame for). The easiest way to try this out would be to create a new compile target inside Svelte itself, but that would be somewhat disruptive for something that may turn out to be completely impossible.

An alternative, which I think is worth doing anyway as it would be good for the codebase, is to break out different compilers into their own packages. So instead of every Node subclass implementing build (for the dom target) and ssr (for the ssr target), the program generated in the initial phase would be handed off to a compiler, which would return something like a { code, map } object (or otherwise something that can be easily turned into one, if that makes more sense in terms of code reuse etc).

So we'd have @sveltejs/compile-dom, @sveltejs/compile-ssr and (eventually) @sveltejs/compile-gl, each implementing the same interface. In time we could even add to that list — @sveltejs/compile-native, @sveltejs/compile-tty and so on.

In all likelihood this would need to be accompanied by separate runtime libraries for the different targets — @sveltejs/lib-dom, @sveltejs/lib-ssr, @sveltejs/lib-common (which dom and ssr would re-export from).

Aside from all the speculative VR stuff, I think this would probably make the codebase less intimidating for new contributors, and it would be good discipline. (The svelte package would still bundle everything, we wouldn't have a nightmarish situation with peer dependencies getting out of sync.)

Any thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    compilerChanges relating to the compiler

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions