A modern, production-ready template for creating Obsidian plugins using Svelte 5 and UnoCSS. This template provides a solid foundation with the latest Svelte features, including runes, while maintaining compatibility with Obsidian's plugin environment.
$state()
, $derived()
)Use this template or clone the repository:
git clone <your-repo-url>
cd your-plugin-name
Install dependencies:
bun install
# or
npm install
Configure your plugin:
package.json
with your plugin detailspublic/manifest.json
with your plugin metadataStart development:
bun run dev
# or
npm run dev
Enable in Obsidian:
├── src/
│ ├── components/ # Svelte components
│ │ ├── ExampleComponent.svelte
│ │ └── Svelte5Features.svelte
│ ├── views/ # Obsidian views
│ │ ├── ExampleView.ts
│ │ └── Svelte5FeaturesView.ts
│ └── main.ts # Plugin entry point
├── public/
│ ├── manifest.json # Plugin manifest
│ └── versions.json # Version compatibility
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
├── vite.config.ts # Build configuration
├── uno.config.ts # UnoCSS configuration
└── biome.json # Code formatting rules
This template showcases several Svelte 5 features:
$state()
: Reactive state management$derived()
: Computed values that update automatically$effect()
: Side effects (use with caution in Obsidian)<script lang="ts">
let count = $state(0);
let doubled = $derived(count * 2);
function increment() {
count++;
}
</script>
<button onclick={increment}>
Count: {count} (doubled: {doubled})
</button>
This template uses Svelte 5 with compatibility mode to ensure proper functioning within Obsidian:
// vite.config.ts
svelte({
compilerOptions: {
compatibility: {
componentApi: 4
}
}
})
This allows you to:
new Component()
)bun run dev
- Start development with hot reloadingbun run build
- Build for productionbun run check
- Run TypeScript and Svelte checksbun run format
- Format code with Biomebun run lint
- Lint code with BiomeThis template uses UnoCSS for styling. You can use Tailwind-like utilities:
<div class="p-4 bg-blue-50 border border-blue-200 rounded-lg">
<h2 class="text-lg font-semibold text-blue-800">Title</h2>
<p class="text-blue-600">Content</p>
</div>
The plugin automatically builds to test-vault/.obsidian/plugins/your-plugin-name/
during development.
bun run build
build/
folder contents to your vault's plugins directoryThis error occurs when Svelte 5's new component API conflicts with Obsidian's environment. This template solves this by:
$destroy()
method for cleanuprm -rf node_modules && bun install
bunx vite build --mode production
bun run check
Contributions are welcome! Please feel free to submit a Pull Request.
This template is available under the MIT License.
If you're migrating from Svelte 4:
let count = 0
with let count = $state(0)
$: doubled = count * 2
with let doubled = $derived(count * 2)
new Component()
for Obsidian compatibility$effect()
sparingly and prefer reactive statements when possible$state()
$state()
, $derived()
, and interactive elementsHappy coding! 🎉