A modern, reusable UI component library built with Svelte 5, featuring TypeScript support and modern development tooling.
# Clone the repository
git clone https://github.com/EliWimmer/svelte-npm-boilerplate.git
cd svelte-npm-boilerplate
# Install dependencies
npm install
# Start development server
npm run dev
A flexible button component with multiple variants and sizes.
Props:
variant?: 'primary' | 'secondary' | 'danger' - Button style variantsize?: 'small' | 'medium' | 'large' - Button sizedisabled?: boolean - Disabled stateonclick?: () => void - Click handlerExample:
<Button variant="primary" size="medium" onclick={handleClick}>
Click me!
</Button>
A card container component for organizing content.
Props:
title?: string - Card titlesubtitle?: string - Card subtitleExample:
<Card title="My Card" subtitle="A simple card">
<p>Card content goes here</p>
</Card>
npm install
Start the development server:
npm run dev
npm run dev - Start development servernpm run build - Build the projectnpm run preview - Preview the built projectnpm run package - Package the library for npmnpm run test - Run Playwright testsnpm run check - Run Svelte type checkingnpm run check:watch - Run type checking in watch modenpm run lint - Lint the codebasenpm run format - Format the codebaseTo package the library for npm:
npm run package
This will create a dist folder with the packaged components ready for publishing.
Before publishing, it's crucial to test your package as if it were installed from npm. Here's the recommended approach:
This method simulates the exact experience users will have when installing your package:
# 1. Build and create a tarball of your package
npm run package
npm pack
This creates a .tgz file (e.g., svelte-npm-boilerplate-1.0.0.tgz) that contains your packaged library.
# 2. Create a test project in a separate directory
cd ..
mkdir package-test && cd package-test
# 3. Create a new Svelte project for testing
npx sv create test-app --template minimal --types ts
cd test-app
npm install
# 4. Install your package from the tarball
npm install ../svelte-npm-boilerplate/svelte-npm-boilerplate-1.0.0.tgz
# 5. Test the components in your test project
# Edit src/routes/+page.svelte:
<script lang="ts">
import { Button, Card } from 'svelte-npm-boilerplate';
let count = 0;
</script>
<main>
<h1>Testing Package Components</h1>
<Card title="Button Test" subtitle="Testing all variants">
<Button variant="primary" onclick={() => count++}>
Increment: {count}
</Button>
<Button variant="secondary" onclick={() => count--}>
Decrement
</Button>
<Button variant="danger" onclick={() => count = 0}>
Reset
</Button>
</Card>
</main>
# 6. Run the test project
npm run dev
npm install github:username/repo-namepackage.jsonnpm run package to build the librarynpm publish to publish to npmsrc/
āāā lib/
ā āāā Button.svelte # Button component
ā āāā Card.svelte # Card component
ā āāā index.ts # Main exports
āāā routes/
ā āāā +layout.svelte # Layout component
ā āāā +page.svelte # Demo page
āāā app.d.ts # Type definitions
This project is built with TypeScript for better developer experience and type safety. All components include proper type definitions that will be available when using the package.
MIT