Share a Svelte component as a link, no build step
AI tools sometimes hand you a Svelte component as a .svelte file. Put it in one HTML file that compiles it in the browser, then upload it and send the link. No npm, no SvelteKit.
A .svelte file holds a <script> block, markup and a <style> block. Browsers cannot run it directly: the Svelte compiler turns it into JavaScript first, normally inside a Vite or SvelteKit project with npm and a deploy.
The compiler also runs in the browser. For one component you want someone to click through, a single HTML file can compile it on load and mount it.
The wrapper
Create a file called app.html with these parts:
- ✓In the head, an import map: <script type="importmap">{ "imports": { "svelte": "https://esm.sh/svelte@5.57.2", "svelte/": "https://esm.sh/svelte@5.57.2/" } }</script>
- ✓In the body, <div id="app"></div>, then a <script type="module">.
- ✓Inside it: import { compile } from 'svelte/compiler'; and import { mount } from 'svelte';
- ✓Paste the whole .svelte file between backticks: const source = `...your component...`;
- ✓In the pasted text, change the component's closing </script> to <\/script>. Otherwise the browser ends the outer script there.
- ✓Then: const { js } = compile(source, { css: 'injected' }); const url = URL.createObjectURL(new Blob([js.code], { type: 'text/javascript' })); const { default: App } = await import(url); mount(App, { target: document.getElementById('app') });
What was tested
Tested in Chrome with Svelte 5.57.2: a component using $state, $derived, bind:value, an onclick handler, an {#each} block and a <style> block rendered, the style applied, and adding an item updated the list and the count, both from a local file and over http.
The compiler is a large download, so the first load takes a few seconds longer than a built app. Components written for Svelte 4 (export let, on:click) also compile under Svelte 5.
If the page shows raw code
Three causes cover most failures:
- ✓You see {count} or {#each} as text, and the console says Unexpected end of input: the component's </script> was not changed to <\/script>.
- ✓A backtick or ${ inside the component code ends or breaks the backtick string. Write them as \` and \${.
- ✓Imports from other packages need an import map entry each, and imports of other .svelte files will not resolve. For a multi-file project, build it to one file instead: sharing a Vite app as a single HTML file.
Upload it and send the link
Drag app.html onto the FileShare Pro dashboard and copy the link. Viewers need no account.
Turn on comments and reviewers can pin notes to parts of the page after typing a name. When you change the component, upload the new app.html over the old one and the link stays the same: updating a shared link without changing it.
Related: sharing a Vue component as a link and sharing a React component as a link.
Frequently asked
A .svelte file has to be compiled to JavaScript before a browser can run it. The wrapper above runs the Svelte compiler on the page.
No. The page loads Svelte and its compiler from a CDN, so you only need a text editor and a browser.
Yes. Double-click app.html; it runs from your computer the same way it runs at the link, as long as you are online for the CDN files.
Yes. The free plan hosts up to 50 files of up to 100 MB each, with view counts and comments included. Password-protected links are on Pro.
Drop the file, copy the link — live in seconds, free plan included.
Start sharing free