Svelte
Svelte apps typically use Vite as their build tool. Heroshot provides a native Svelte component and Vite plugin that work together.
Using SvelteKit?
See the SvelteKit integration instead - it's the same component with SSR support.
Getting Started
Install heroshot:
npm install heroshotThen run it:
npx heroshotThis opens a browser with the visual picker. Start your dev server (npm run dev), navigate to it in the heroshot browser, click on elements you want to capture, and close when done.
Where to Put Screenshots
Vite serves anything in public/ at the root URL. Set your heroshot output directory to public/heroshots so screenshots are served as /heroshots/whatever.png:
// .heroshot/config.json
{
"outputDirectory": "public/heroshots"
}Setting Up the Plugin
Add the Vite plugin to your config:
// vite.config.ts
import { svelte } from '@sveltejs/vite-plugin-svelte';
import { heroshot } from 'heroshot/plugins/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [svelte(), heroshot()],
});That's it. The plugin auto-registers the manifest when you import the <Heroshot> component.
Using Screenshots
Use the <Heroshot> component in any Svelte file:
<script>
import { Heroshot } from 'heroshot/svelte';
</script>
<Heroshot name="Dashboard" alt="Dashboard overview" />The component handles:
- Light/dark mode - Automatically switches based on your app's theme
- Responsive viewports - Uses
<picture>with media queries when you have multiple viewport variants - Lazy loading - Images load lazily by default
Props
| Prop | Type | Description |
|---|---|---|
name | string | Screenshot name (as defined in heroshot config) |
alt | string | Alt text for accessibility |
class | string | CSS class to apply to the image |
Dark Mode Detection
The component detects dark mode by checking:
.darkclass - Used by Tailwind, mode-watcher, and many Svelte UI libraries (<html class="dark">)prefers-color-scheme- Browser/OS preference
It watches for changes via MutationObserver and media query listeners, so theme toggles work instantly.