Developing Browser Extensions with Vue.js based on Vite.
-
The extension manifest is defined in
src/manifest.ts
and used by@samrum/vite-plugin-web-extension
in the vite config. -
Background
,content scripts
,options
, andpopup
entry points exist in thesrc/entries
directory. -
Content scripts
are rendered bysrc/entries/content/index.ts
-renderContent
function which renders content within a ShadowRoot and handles style injection for HMR and build modes. -
Otherwise, the project functions just like a regular
Vite
project. -
HMR
during development inManifest V3
requiresChromium version >= 110.0.5480.0
. -
Using the UnoCSS Atomic CSS engine in
Content scripts
,options
, andpopup
.
Refer to @samrum/vite-plugin-web-extension for more usage notes.
See Vite Configuration Reference.
To clone repo:
bunx degit heybrostudio/vite-webext-vue [your-project-name]
To install dependencies:
bun install
Hot Module Reloading is used to load changes inline without requiring extension rebuilds and extension/page reloads Currently only works in Chromium based browsers.
bun run dev
Rebuilds extension on file changes. Requires a reload of the extension (and page reload if using content scripts)
bun run dev:watch
Minifies and optimizes extension build
bun run build
Bump version and extension build
bun run release
Using taze to detect dependency versions
bun run up
Automatically zip after build via vite-plugin-fflate-zip
// vite.config.ts
// ...
import fflateZip from 'vite-plugin-fflate-zip'
export default defineConfig(({ mode }) => {
return {
plugins: [
// ...
webExtension({
manifest: getManifest(),
}),
fflateZip({
inDir: 'dist/build',
}),
],
// ...
}
})
Loads the contents of the dist/dev
directory into the specified browser
bun run serve:chrome
bun run serve:firefox