npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vite-plugin-webext

v1.2.18

Published

A vite plugin for generating cross browser platform, ES module based web extensions

Downloads

20

Readme

vite-plugin-webext

version ci

A Vite plugin to generate cross-browser web extensions, available for Chrome, Edge, Firefox, Opera etc...

With this plugin, you can build a browser extension compatible with all browsers with modern technologies like typescript, tailwind and react.

Features

  • Supports manifest v3 & v2
  • ES-module-based extension
  • HTML and static assets handling
  • HMR support in shadow-dom
  • CSS compiling
  • Support for sass, tailwind and more

Getting started

Create a Vite project and install the package

npm install vite-plugin-webext

update the vite.config.ts like this

// vite.config.ts

import { defineConfig } from 'vite'
import webExtension from 'vite-plugin-webext'
import manifest from './manifest'

export default return defineConfig({
  ...
  plugins: [
    webExtension({ manifest: manifest }),
  ],
})

Typescript Support

Create an env.d.ts file, and add the following type reference to define the plugin-specific import.meta variables

// env.d.ts
/// <reference types="vite-plugin-webext/client" />

Browser Support

The following requirements must be met by the browser:

  • Must support dynamic module imports made by web extension content scripts.
  • Must support import.meta.url

The plugin will automatically default to 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, the Chromium version must be at least 110.

How it works

The plugin will take the provided manifest, generate rollup input scripts for supported manifest properties, and then output an ES module-based web extension.

This includes:

  • Generating and using a dynamic import wrapper script in place of original content scripts. Also adds the scripts to web_accessible_resources so they are accessible from content-scripts. This is because content scripts are not able to be loaded directly as ES modules.
  • This may expose your extension to fingerprinting by other extensions or websites. Manifest V3 supports a use_dynamic_url property that will mitigate this. This option is set for manifest V3 web-accessible resources generated by this plugin.
  • Modifying Vite's static asset handling to maintain import.meta.url usages instead of rewriting to self.location for wider browser support.
  • Modifying Vite's HMR client to add support for targeting specific elements as style injection locations. Needed to support HMR styles in shadow DOM rendered content.