Gathering detailed insights and metrics for @haruleekim/vite-plugin-web-extension
Gathering detailed insights and metrics for @haruleekim/vite-plugin-web-extension
Gathering detailed insights and metrics for @haruleekim/vite-plugin-web-extension
Gathering detailed insights and metrics for @haruleekim/vite-plugin-web-extension
A vite plugin for generating cross browser platform, ES module based web extensions.
npm install @haruleekim/vite-plugin-web-extension
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (91.17%)
JavaScript (4.16%)
HTML (3.7%)
CSS (0.86%)
Shell (0.06%)
SCSS (0.05%)
Total Downloads
360
Last Day
1
Last Week
7
Last Month
14
Last Year
134
MIT License
349 Stars
128 Commits
30 Forks
7 Watchers
2 Branches
10 Contributors
Updated on Jul 01, 2025
Latest Version
3.0.1
Package Id
@haruleekim/vite-plugin-web-extension@3.0.1
Unpacked Size
95.75 kB
Size
19.37 kB
File Count
8
NPM Version
8.19.3
Node Version
18.13.0
Published on
Feb 05, 2023
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
133.3%
7
Compared to previous week
Last Month
7.7%
14
Compared to previous month
Last Year
3.9%
134
Compared to previous year
Generate cross browser platform, ES module based web extensions.
Create a new Vite web extension project
1npm init @samrum/vite-plugin-web-extension@latest
Supports choice of Manifest version, TypeScript support, and framework (Vanilla, Vue, React, Preact, Svelte).
Check the README of the generated extension for usage information.
Requires Vite 3+
1npm install @samrum/vite-plugin-web-extension
vite.config.js:
1import { defineConfig } from "vite"; 2import webExtension from "@samrum/vite-plugin-web-extension"; 3 4export default defineConfig({ 5 plugins: [ 6 webExtension({ 7 manifest: { 8 name: pkg.name, 9 description: pkg.description, 10 version: pkg.version, 11 manifest_version: 2, 12 background: { 13 scripts: ["src/background/script.js"], 14 }, 15 }, 16 }), 17 ], 18});
vite.config.js:
1import { defineConfig } from "vite"; 2import webExtension from "@samrum/vite-plugin-web-extension"; 3 4export default defineConfig({ 5 plugins: [ 6 webExtension({ 7 manifest: { 8 name: pkg.name, 9 description: pkg.description, 10 version: pkg.version, 11 manifest_version: 3, 12 background: { 13 service_worker: "src/background/serviceWorker.js", 14 }, 15 }, 16 }), 17 ], 18});
Background service workers are not supported, so you are required to use a background script.
The use_dynamic_url
property is not supported for web accessible resources. In the plugin options, set useDynamicUrlContentScripts
to false:
1 webExtension({ 2 ... 3 useDynamicUrlContentScripts: false, 4 }),
1devtools_page: "src/entries/devtools/index.html",
Place a script devtools.js
in public
dir.
1var _browser; 2if (chrome) { 3 _browser = chrome; 4} else { 5 _browser = browser; 6} 7_browser.devtools.panels.create( 8 "My Panel", // title 9 "images/icon-16.png", // icon 10 "src/entries/devtools/index.html" // content 11);
Then load the script from your devtools html which placed in src/entries/devtools/index.html
.
1<!DOCTYPE html> 2<html lang="en"> 3 <head> 4 <meta charset="UTF-8" /> 5 <title>Devtools</title> 6 </head> 7 <body> 8 <div id="app"></div> 9 <script type="module" src="./main.ts"></script> 10 <script src="/devtools.js"></script> 11 </body> 12</html>
manifest
useDynamicUrlContentScripts: boolean (optional)
use_dynamic_url
property to web accessible resources generated by the plugintrue
webAccessibleScripts: rollup filter (optional)
web_accessible_resources
entries in the provided manifest. When the filter matches a resource, it will be parsed by the plugin and treated as a content script. This can be useful to generate content scripts that will be manually injected at runtime.1{ 2 include: /\.([cem]?js|ts)$/, 3 exclude: "", 4}
For HMR style support within shadow DOMs, use the addStyleTarget
function to add the shadowRoot of your element as a style target:
1if (import.meta.hot) { 2 const { addViteStyleTarget } = await import( 3 "@samrum/vite-plugin-web-extension/client" 4 ); 5 6 await addViteStyleTarget(appContainer); 7}
For builds, use the import.meta.PLUGIN_WEB_EXT_CHUNK_CSS_PATHS
variable to reference an array of CSS asset paths associated with the current output chunk.
In an env.d.ts file, add the following type reference to define the plugin specific import.meta
variables as well as plugin client functions:
1/// <reference types="@samrum/vite-plugin-web-extension/client" />
The following requirements must be met by the browser:
import.meta.url
A sample of supported browsers:
Manifest V2 | Manifest V3 | |
---|---|---|
Chromium | 64 | 91 |
Firefox | 89 | N/A (In development) |
The plugin will automatically default vite's build.target
config option to these minimum browser versions if not already defined by the user.
For dev mode support in Manifest V3, Chromium version must be at least 110.
The plugin will take the provided manifest, generate rollup input scripts for supported manifest properties, then output an ES module based web extension.
This includes:
web_accessible_resources
so they are accessible by the wrapper script. Needed because content scripts are not able to be loaded directly as ES modules.
use_dynamic_url
property that will mitigate this. This option is set for manifest V3 web accessible resources generated by this plugin.import.meta.url
usages instead of rewriting to self.location
. Needed so content script static asset handling can function correctly.The plugin relies on Vite to parse and handle html files in addition to relying on Vite's manifest generation in order to map generated files to the eventual extension manifest.
This project uses pnpm for package management.
1pnpm lint
1pnpm test
1pnpm build
No vulnerabilities found.
No security vulnerabilities found.