- Separate package (monorepo or standalone repo)
- Each component: Typed props, typed emits, slots for flexibility
- Documentation: VitePress or Storybook with interactive examples
- Design tokens: CSS custom properties for theming (
--color-primary, etc.) - Testing: Vitest for unit tests + visual regression tests
- Versioning: Semver so teams can upgrade at their own pace
- Tree-shaking: Named exports so only what's used gets included
- Accessibility: ARIA, keyboard navigation, focus management
ts
// Good library component
<script setup lang="ts">
interface Props {
variant?: 'primary' | 'secondary' | 'danger'
size?: 'sm' | 'md' | 'lg'
disabled?: boolean
}
withDefaults(defineProps<Props>(), {
variant: 'primary',
size: 'md',
disabled: false
})
defineEmits<{ click: [event: MouseEvent] }>()
</script>