svelte-webcomponent Svelte Themes

Svelte Webcomponent

Starter pack for anyone who want to write super-tiny webcomponent using svelte

Svelte Web Components Starter

A lightweight starter template for building optimized web components with Svelte 5 and TypeScript. Produces production-ready components with:

  • 20KB minified (ES format)
  • 8KB gzipped
  • Custom Elements v1 compliant

Features

āš”ļø Ultra-lightweight output
šŸ›  TypeScript-first development
šŸŒ Universal component format (ES + UMD)
šŸ”§ Built-in Vite optimizations
šŸŽÆ CSS isolation per component
šŸ“¦ Zero-dependency components

Quick Start

Installation

npm install

Development

npm run dev

Production Build

npm run build

Preview Production Build

npm run preview

Usage

Import in HTML

<script type="module" src="/dist/my-web-components.es.js"></script>

<my-component name="Developer"></my-component>

Use in JavaScript

import { MyComponent } from './dist/my-web-components.es.js';

// Components auto-register on import

Building Components

  1. Create new component in src/wc/ ```svelte <svelte:options customElement="my-element" />
Hello {value}
```
  1. Add to src/wc/web-components.ts

    export { default as MyElement } from './MyElement.wc.svelte';
    
  2. Rebuild with npm run build

Package Scripts

Command Description
npm run dev Start dev server with HMR
npm run build Build production-ready components
npm run preview Locally preview production build
npm run check Validate TypeScript types

Technical Stack

Core Technologies

  • Svelte 5 (custom elements)
  • TypeScript 5
  • Vite 6

Optimization Features

  • Double minification (Terser + esbuild)
  • Tree-shaking enabled
  • CSS auto-scoping
  • Dead code elimination
  • Gzip-ready outputs

File Structure

ā”œā”€ā”€ src/
ā”‚   ā”œā”€ā”€ wc/                   # Web components
ā”‚   ā”‚   ā”œā”€ā”€ MyComponent.wc.svelte
ā”‚   ā”‚   ā””ā”€ā”€ web-components.ts # Component registry
ā”‚   ā”œā”€ā”€ lib/                  # Svelte components
ā”‚   ā”œā”€ā”€ App.svelte            # Demo application
ā”‚   ā””ā”€ā”€ main.ts               # Entry point
ā”œā”€ā”€ vite.config.ts            # Build configuration
ā””ā”€ā”€ svelte.config.js          # Svelte compiler settings

License

MIT Ā© Dariusz Sikorski


Made with ā™„ by Dariusz Sikorski

Top categories

Loading Svelte Themes