Svelte Chrome Extension Boilerplate

A minimal boilerplate for developing Chrome extensions with Svelte and Vite.

Features

  • šŸ”„ Hot Module Replacement (HMR) for development
  • āš”ļø Blazing fast build with Vite
  • šŸ’Ŗ Type safety with Svelte 5
  • šŸ“± Organized structure with clear separation of concerns
  • šŸŽØ Modern setup with ESM and latest Chrome Extension Manifest V3

Project Structure

svelte-chrome-extension-boilerplate/
ā”œā”€ā”€ public/                  # Static files
ā”‚   ā”œā”€ā”€ assets/              # Icons and assets
ā”‚   ā””ā”€ā”€ manifest.json        # Extension manifest
ā”œā”€ā”€ src/
ā”‚   ā”œā”€ā”€ popup/               # Popup UI
ā”‚   ā”‚   ā”œā”€ā”€ popup.html
ā”‚   ā”‚   ā”œā”€ā”€ popup.js
ā”‚   ā”‚   ā””ā”€ā”€ Popup.svelte
ā”‚   ā”œā”€ā”€ newtab/              # New Tab page
ā”‚   ā”‚   ā”œā”€ā”€ index.html
ā”‚   ā”‚   ā”œā”€ā”€ index.js
ā”‚   ā”‚   ā”œā”€ā”€ index.css
ā”‚   ā”‚   ā””ā”€ā”€ NewTab.svelte
ā”‚   ā”œā”€ā”€ background/          # Background script
ā”‚   ā”‚   ā””ā”€ā”€ background.js
ā”‚   ā””ā”€ā”€ content_scripts/     # Content scripts
ā”‚       ā”œā”€ā”€ content.js
ā”‚       ā””ā”€ā”€ content.css
ā””ā”€ā”€ vite.config.js           # Vite configuration

Getting Started

Installation

# Clone the repo (or download)
git clone https://github.com/your-username/svelte-chrome-extension-boilerplate.git

# Install dependencies
npm install

Development

# Start development server
npm run dev

# For popup development specifically
npm run dev:popup

# For new tab page development specifically
npm run dev:newtab

Building for Production

# Build the extension
npm run build

This creates a dist folder with the following structure:

dist/
ā”œā”€ā”€ popup/                # Popup UI files
ā”œā”€ā”€ newtab/               # New tab page files
ā”œā”€ā”€ background/           # Background script
ā”œā”€ā”€ content_scripts/      # Content scripts
ā”œā”€ā”€ shared/               # Shared chunks
ā”œā”€ā”€ assets/               # Icons and assets
ā””ā”€ā”€ manifest.json         # Extension manifest

Loading the Extension in Chrome

  1. Build the project with npm run build
  2. Open Chrome and navigate to chrome://extensions
  3. Enable "Developer mode"
  4. Click "Load unpacked extension"
  5. Select the dist folder

Customization

This boilerplate comes with minimal implementations for all extension components. You can:

  • Modify src/popup/Popup.svelte for the popup UI
  • Edit src/newtab/NewTab.svelte for the new tab page
  • Update src/background/background.js for background functionality
  • Change src/content_scripts/content.js for page interaction

License

MIT

Top categories

svelte logo

Need a Svelte website built?

Hire a professional Svelte developer today.
Loading Svelte Themes