Skip to content

Behind-the-curtains: how do I "manually compile" *.svelte files directly without any "vite / rollup / webpack / other-bundler"? #11830

Answered by paoloricciuti
metaleap asked this question in Q&A
Discussion options

You must be logged in to vote

You are about to embark in a very painful travel because you will basically need to re-invent the whole vite-plugin-svelte (which btw could serve you as a starting point) 😄

As you mentioned there's some documentation about the compiler:

import { compile } from 'svelte/compiler';
const result = compile(source, {
	// options
});

this is technically all you need to compile a svelte component to JS.

Here i have a small compiler playground...if you write your svelte component in the textarea you can see the result of the compilation in the object below.

As you can see is as simple as calling compile with the string of your component and you get back an object with a bunch of properties: js whi…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@metaleap
Comment options

@paoloricciuti
Comment options

@Prinzhorn
Comment options

Answer selected by metaleap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants