|
Is there a way to compile string to svelte Component class? Imagine we have component code in database as string, network fetch or read local file as string:
and we need to parse it as AST and render like this comment: sveltejs/svelte#9377 (comment) with Is there a solution how to create SSR component from string? React have similar parsers to JSX from string: |
Answered by
teemingc
Mar 28, 2024
Replies: 1 comment 5 replies
|
Something like this? import { compile } from 'svelte/compiler';
const result = compile('<div class="container">Hello world</div><style></style>', { generate: 'ssr' }).render(); |
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dug into it a bit more: compiling the JS code for the Svelte component and writing it to disk works. Then, we dynamically import the module on disk, call
render, and get the html and css. Hope this helps!