A web extension template built using Svelte 5, TypeScript, and Vite. Supports both Firefox and Chromium, with a fast dev and build pipeline.
# Clone this repo
git clone https://github.com/atif-c/Starter-Web-Extension
cd starter-web-extension
# Install dependencies
npm install
# Start development (Firefox)
npm run dev
Your extension will be built and loaded in Firefox with auto-reload enabled
npm run dev
This will:
Build for specific browser:
npm run build:firefox # Firefox only
npm run build:chromium # Chromium only
Build for both browsers:
npm run build # Both Firefox and Chromium
npm run watch:firefox # Watch and rebuild changes for Firefox
npm run watch:chromium # Watch and rebuild changes for Chromium
npm run build:firefox
or npm run dev
about:debugging
dist/firefox/
directorynpm run build:chromium
chrome://extensions/
dist/chromium/
directory├── build.js # Custom build script for extension packaging
├── src/
│ ├── assets/logo/ # Extension icons (16, 32, 48, 128px + SVG)
│ ├── lib/
│ │ ├── components/ # Svelte components
│ │ ├── storage/ # Persistent Storage system
│ │ ├── utils/ # Utility files
│ │ └── background.js # Background script
│ ├── manifests/ # Manifest files
│ └── popup/ # Extension popup
│ ├── popup.css
│ ├── popup.html
│ ├── Popup.svelte
│ └── popup.ts
├── dist/ # Build outputs
│ ├── chromium.zip
│ ├── firefox.zip
│ ├── chromium/
│ ├── firefox/
│ └── vite-output/
├── package.json
├── svelte.config.js
├── tsconfig.json
├── vite.config.ts
└── web-ext-config.mjs # Firefox web-ext configuration
build.js
- Custom build script that merges the base manifest with browser-specific overrides, injects the version from package.json, combines the vite output, and generates optimised builds in the dist/ directory for both Firefox and Chromiumsrc/lib/Components/Counter.svelte
- Displays and updates the count
value, showcasing state managementsrc/popup/popup.css
- Styles the popup pagesrc/popup/popup.html
- HTML container for the popupsrc/popup/Popup.svelte
- Root Svelte component for the extension’s popup interfacesrc/popup/popup.ts
- Mounts the Popup
component to the popup pagesrc/lib/storage/default-object.ts
- Holds the default storage object used for validationsrc/lib/storage/state-manager.svelte.ts
- Generic state management class for managing reactive object state with automatic persistence.src/lib/storage/state.svelte.ts
- Provides a $state variable variable linked to persistent storage, automatically loads data on start, saves changes back to storage, and validates data to prevent loading or saving malformed valuessrc/lib/storage/utils.ts
- Handles a variable that defines whether browser.storage should use local or sync storage, and provides the cleanObject function for data validationThe template uses a three-part manifest system:
src/manifests/manifest.base.json
- Base manifest containing properties that should be used for all extension build targetssrc/manifests/manifest.chromium.json
- Chromium-specific manifest overrides and additionssrc/manifests/manifest.firefox.json
- Firefox-specific manifest overrides and additionsThe build script automatically merges these files and injects the current version from package.json
src/lib/background.js
- Placeholder background script where you can add background processes, event listeners, and service worker functionalitysrc/lib/utils/debounce.ts
- Debounce helper for the autosave system, rapid changes to stored data doesn’t trigger excessive save operations.The template includes a reliable storage system:
local
vs sync
)The development setup is optimised for rapid iteration:
Replace the logo files in src/assets/logo/
with your own icons. You need:
logo-16.png
(16x16)logo-32.png
(32x32)logo-48.png
(48x48)logo-128.png
(128x128)logo.svg
(vector source)Use svg-2-png to generate all required PNG sizes from your SVG logo
Script | Description |
---|---|
npm run dev |
Full development mode (Firefox) |
npm run build |
Build for both browsers |
npm run build:firefox |
Build Firefox extension |
npm run build:chromium |
Build Chrome extension |
npm run watch:firefox |
Watch files and rebuild for Firefox |
npm run watch:chromium |
Watch files and rebuild for Chrome |
npm run start:firefox |
Launch Firefox with extension |
npm run vite:dev |
Vite development server |
npm run vite:build |
Vite build only |
npm run check |
TypeScript and Svelte type checking |
Production-ready ZIP files are automatically created in dist/
:
firefox.zip
chromium.zip