Bootswatch theme switcher Web Component with
- dark mode
- compact/invisible options
- Vite dev environment
- Offline-ready
- ✅ Runtime theme switching among all Bootswatch v5 themes plus default Bootstrap
- ✅ Dark mode toggle via Bootstrap 5.3
data-bs-theme - ✅ Configurable via element attributes (paths, defaults, visibility)
- ✅ Persistence via
localStorage(bootswatcher:theme&bootswatcher:mode) - ✅ Preload script applies saved theme & mode early to prevent FOUC
- ✅ Automatic link insertion if missing (
insert-linkattribute) - ✅ Local copies of Bootswatch CSS and Bootstrap assets (JS & CSS)
- ✅ TypeScript source → ESM & IIFE bundles + types
- ✅ Node.js build script (
build.js) - ✅ Optional
setup-webpack.jsto scaffold a minimal webpack config - ✅ Vite dev environment (
vite.config.ts) withpnpm dev - ✅ ESLint/Prettier setup for TypeScript & Web Components
- ✅ GitHub Action to build and publish
dist/(GitHub Pages)
pnpm install
pnpm dev # Vite dev server at http://localhost:5173
pnpm run build # Production build (offline dist/)
pnpm dlx serve dist<boot-swatcher/><boot-swatcher
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
></boot-swatcher>themes-url: URL to JSON array of theme names (auto-generated at build). Default:./themes/themes.jsonthemes-path: Directory containing CSS themes. Default:./themeslink-id: The<link>element id used for active theme. Default:bootswatch-themedefault-theme: Fallback if no saved theme. Default:bootstrapdefault-mode:light|dark|auto(auto respects OS preference). Default:autoshow-label: Present to show the "Theme" labelshow-mode-toggle: Present to show dark mode togglecompact: Present to render a smaller UI footprintinvisible: Present to apply theme/mode without rendering controlsinsert-link: Present to create the<link id="...">if it doesn't exist
setTheme(name: string)setMode(mode: 'light' | 'dark')
- Detects available package manager (
pnpm→npm→yarn) and uses the right commands. - Uses
node build.js
MIT