A Vite powered WebExtension (Chrome, FireFox, etc.) starter template.
- ⚡️ Instant HMR - use Vite on dev (no more refresh!)
- 🥝 React 17
- 🦾 TypeScript - type safe
- 🖥 Content Script - Use React even in content script
- 🌍 WebExtension - isomorphic extension for Chrome, Firefox, and others
- 📃 Dynamic
manifest.jsonwith full type support
webextension-polyfill- WebExtension browser API Polyfill with types
@vitejs/plugin-react- React plugin for Vite.
- TypeScript
- 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
npx degit bas-d/vite-react-browser-extension-template my-webext
cd my-webext
npm isrc- main source.content- scripts and components to be injected ascontent_scriptbackground- scripts for background.page- example page in your extensioncomponents- React components.manifest.ts- manifest for the extension.
build- extension package root.assets- static assets.dist- built files, also serve stub entry for Vite on development.
scripts- development and bundling helper scripts.
npm devThen load extension in browser with the build/ folder.
For Firefox developers, you can run the following command instead:
npm start:firefoxweb-ext auto reload the extension when extension/ files changed.
While Vite handles HMR automatically in the most of the case, Extensions Reloader is still recommanded for cleaner hard reloading.
To build the extension, run
npm buildAnd then pack files under build, you can upload extension.crx or extension.xpi to appropriate extension store.
This template is originally made by Anthony Fu and adopted to work with React.