Bootswatch theme switcher Web Component
npm install bootswatcherBootswatch theme switcher Web Component
with
- dark mode
- compact/invisible options
- Vite dev environment
- Offline-ready
data-bs-themelocalStorage (bootswatcher:theme & bootswatcher:mode)insert-link attribute)build.js)setup-webpack.js to scaffold a minimal webpack configvite.config.ts) with pnpm devdist/ (GitHub Pages)---
``sh`
pnpm install
pnpm dev # Vite dev server at http://localhost:5173
pnpm run build # Production build (offline dist/)
pnpm dlx serve dist
---
html
`$3
`html
themes-url="./themes/themes.json"
themes-path="./themes"
link-id="bootswatch-theme"
default-theme="bootstrap"
default-mode="auto"
show-label
show-mode-toggle
compact
insert-link
>
`$3
- themes-url: URL to JSON array of theme names (auto-generated at build). Default: ./themes/themes.json
- themes-path: Directory containing CSS themes. Default: ./themes
- link-id: The element id used for active theme. Default: bootswatch-theme
- default-theme: Fallback if no saved theme. Default: bootstrap
- default-mode: light | dark | auto (auto respects OS preference). Default: auto
- show-label: Present to show the "Theme" label
- show-mode-toggle: Present to show dark mode toggle
- compact: Present to render a smaller UI footprint
- invisible: Present to apply theme/mode without rendering controls
- insert-link: Present to create the if it doesn't exist$3
- setTheme(name: string)
- setMode(mode: 'light' | 'dark')---
Windows-friendly build script
- Detects available package manager (pnpm → npm → yarn) and uses the right commands.
- Uses node build.js` ---