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

webpack-browser-extension-plugin

v1.3.0

Published

A webpack extension that has auto reload, and some built in tools to help webpack browser extension development.

Downloads

18

Readme

Webpack Browser Extension Plugin

npm install webpack-browser-extension-plugin

Only currently support webpack 4.x

This is a webpack plugin that currently just sets up some auto reloading for Browser Extensions that uses the browser API to setup some optimal reloading, with plans on Supporting HMR, and React refresh in the future.

Although there are a few other plugins out there, most of them get in the way when expanding your browser usage or upgrading to v3 of the Chrome manifest. This plugin takes all the findings from those experiences and combines it one plugin.

  • Inject into bundle for background process since v3 does not support loading two files in the background service worker
  • Avoid using look behind regexp to allow for usage in Safari web extensions.
  • Auto reload on change in manifest.json or locales.

Note: This has not yet been tested on Safari, and pretty sure it might not still work due to xcode compilation issues.

Usage

Adding the plugin

You will want to add this plugin to the plugin array in your webpack config.

import { BrowserExtensionPlugin } from 'webpack-browser-extension-plugin'

{
  plugins: [
    new BrowserExtensionPlugin({
      autoReload: isWatch ? true : false,
      backgroundEntry: 'background',
      ignoreEntries: ['bootstrap'],
    }),
  ]
}

In the example above we are setting a few options.

  • autoReload: This tells the plugin to run the socket server, should only be done in development and when you are watching files.

  • backgroundEntry: This tells the plugin which entry is your background entry. This is super important because the background entry orchestrates reloading of client scripts.

  • ignoreEntries [Optional]: This tells the plugin which entries to not inject auto reload code into. These can be scripts that are short lived or utility scripts. default: []

Structure of entries

For this plugin to work we need a named key of entries to keep track of which entry is which. For example:

{
  "entry": {
    "background": "./src/background.js",
    "content": "./src/content.js"
  }
}

This allows the plugin to know when passing "background" to backgroundEntry what that entry is, and also which scripts should connect to the background.

How it works

Different plugins work a bit differently. This plugin essentially uses the background process to coordinate updates. The websocket server is connected to the background process. The background process checks to see if it needs to reload, if so it messages clients that they will need to do a delayed reload because the extension context is changing. If the background script does not need to reload. It sends a message to the clients via a port to see if they need to update, if they need to update they reload on their own. Kinda like a React tree only the pieces of the tree that need to be updated are updated.

Additional options

  • manifestPath [optional]: This tells the plugin where the manifest is located.
  • onCompileManifest [optional]: This is a function that is called when the manifest is compiled and you can do any additional processing of the manifest.
  • localesDirectory [optional]: This is the directory that contains the locale files.
  • port [optional]: the port for the socket server to listen on. port: 9090
  • host [optional]: the host string that the socket server is served from. default: localhost
  • reconnectTime [optional]: the time the plugin waits to re-establish connections to socket server and browser ports. default: 3000
  • quiet [optional]: quiet logging in the clients, and terminal process. default: false

Prior art