Creating Component Plugins
Component plugins allow you to create reusable Svelte components that can be used across Evidence projects. This guide covers creating, packaging, and publishing component plugins.Plugin Structure
A component plugin is an npm package that exports Svelte components with specific Evidence metadata.Package Structure
Package Configuration
package.json
The
evidence.components field can be:true- Components are exported from the main entry pointstring- Path to a custom file exporting components
Component Plugin Interface
Component Metadata
Component Manifest Schema
Creating Components
Basic Component
src/lib/Button/Button.svelte
Data-Connected Component
src/lib/DataTable/DataTable.svelte
Chart Component
src/lib/Chart/LineChart.svelte
Exporting Components
Component Index Files
Each component should have an index file:src/lib/Button/index.js
src/lib/DataTable/index.js
Main Index File
Export all components from the main index:src/lib/index.js
Build Configuration
SvelteKit Package Config
svelte.config.js
Vite Configuration
vite.config.js
Component Plugin Loading
Evidence loads component plugins through this process:Component Overrides
Plugins can override components from other plugins:evidence.config.yaml
Override Validation
Real Example: Core Components
The official@evidence-dev/core-components package structure:
package.json
src/lib/index.js
src/lib/atoms/index.js
Development Workflow
Best Practices
Component Props
Type Safety
Use JSDoc for type hints:Styling
Accessibility
Testing
Create component tests:src/lib/Button/Button.test.js