A Vite powered WebExtension (Chrome, FireFox, etc.) starter template.
Popup
Options Page
Inject React iframe-app into the Content Script
- ⚡️ Instant HMR - use Vite on dev (no more refresh!)
- ⚛️ - Use React with Hooks and more.
- 💬 Effortless communications - powered by
webext-bridge
- 🌈 UnoCSS - The instant on-demand Atomic CSS engine.
- 🦾 TypeScript - type safe
- 📦 Components auto importing
- 🌟 Icons - Access to icons from any iconset directly
- 🖥 Content Script - Use React even in content script
- 🌍 WebExtension - isomorphic extension for Chrome, Firefox, and others
- 📃 Dynamic
manifest.json
with full type support
webextension-polyfill
- WebExtension browser API Polyfill with typeswebext-bridge
- effortlessly communication between contexts
unplugin-auto-import
- Directly usebrowser
and Vue Composition API without importingunplugin-icons
- icons as components@vitejs/plugin-react
- React plugin for Vite.
- tbd
- UnoCSS - the instant on-demand Atomic CSS engine
- ESLint with @antfu/eslint-config, single quotes, no semi
- TypeScript
- pnpm - fast, disk space efficient package manager
- esno - TypeScript / ESNext node runtime powered by esbuild
- npm-run-all - Run multiple npm-scripts in parallel or sequential
- web-ext - Streamlined experience for developing web extensions
Create a repo from this template on GitHub.
If you prefer to do it manually with the cleaner git history
If you don't have pnpm installed, run: npm install -g pnpm
npx degit louisremi/vite-react-extension my-webext
cd my-webext
pnpm i
src
- main source.contentScript
- scripts and components to be injected ascontent_script
background
- scripts for background.components
- auto-imported Vue components that are shared in popup and options page.styles
- styles shared in popup and options pageassets
- assets used in Vue componentsmanifest.ts
- manifest for the extension.
extension
- extension package root.assets
- static assets (mainly formanifest.json
).dist
- built files, also serve stub entry for Vite on development.
scripts
- development and bundling helper scripts.
pnpm dev
Then load extension in browser with the extension/
folder.
For Firefox developers, you can run the following command instead:
pnpm start:firefox
web-ext
auto reload the extension when extension/
files changed.
While Vite handles HMR automatically in most of the case, Extensions Reloader is still recommanded for cleaner hard reloading.
To build the extension, run
pnpm build
And then pack files under extension
, you can upload extension.crx
or extension.xpi
to appropriate extension store.
- Forked from antfu/vitesse-webext, the original WebExtension Vite+Vue starter template.
- React port originally based on sohcah/vite-react-webext
- bas-d/vite-react-browser-extension-template has a solution to write firefox and chrome extensions at the same time. His template is also less opinionated (but its not compatible with Manifest v3 and my fork is more up-to-date, and easier to keep updated with the original)