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

web-ext-react

v1.1.2

Published

Command line tool to help build, run and test ReactJS based WebExtensions

Downloads

4

Readme

Node.js CI

web-ext-react

A CLI tool to help build and run ReactJS based WebExtensions, integrating web-ext with create-react-app

Highlights

Create ReactJS Web Extensions with no build configuration.

  • No forked dependencies, uses create-react-app and web-ext as is, enabling you to easily keep up to date.
  • Live reload of JavaScript and CSS as you work on your extension.

Limitations

This is a work in progress extracted from race-ext-react. Ideally web-ext-react would wrap web-ext and work as a drop in replacement for better ergonomics, while adding the additional React functionality.

Documentation

web-ext-react should be used with a project created with create-react-app. After creating a new react app with create-react-app my-app install web-ext-react and web-ext.

npm

npm install --save-dev web-ext web-ext-react

yarn

yarn add -D web-ext web-ext-react

Next you can add scripts to package.json

"scripts": {
  "start:firefox": "web-ext-react run | xargs -L1 web-ext run -u http://www.example.org/ -s",
  "build": "web-ext-react build | web-ext build -o -s"
}

index.js

create-react-app creates a single app that can be used for all different aspects of a web extensions, content scripts, background script, popups, sidebar and options ui by adding conditional logic to the src/index.js auto generated by create-react-app, for example.

if (document.isBackground) {
  // some background script
} else if (document.isSidebarAction) {
  ReactDOM.render(
    <React.StrictMode>
      <Sidebar />
    </React.StrictMode>,
    document.getElementById("root")
  );
} else if (document.isBrowserAction) {
  ReactDOM.render(
    <React.StrictMode>
      <Popup />
    </React.StrictMode>,
    document.getElementById("root")
  );
} else if (document.isOptionsUi) {
  ReactDOM.render(
    <React.StrictMode>
      <Options />
    </React.StrictMode>,
    document.getElementById("root")
  );
} else if (document.isContentScripts) {
  // content script
  ReactDOM.render(
    <React.StrictMode>
      <App />
    </React.StrictMode>,
    document.getElementById("root")
  );
}

extension/manifest.json

You must create an extension/manifest.json

{
  "manifest_version": 2,
  "name": "web-ext-react dummy app",
  "version": "0.1",

  "description": "dummy app to test web-ext-react",
  "homepage_url": "https://github.com/mrloop/web-ext-react",
  "icons": {
    "48": "icon.svg",
    "96": "icon.svg"
  },
  "content_scripts": [
    {
      "matches": ["*"],
      "js": [],
      "css": []
    }
  ],
  "background": {
    "page": "background-page.html"
  }
}

Note the "content_scripts" JS and CSS arrays are empty and will be populated at build time. We specify that the web extension will also run a background script, also note "background-page.html" is auto generated by web-ext-react. You don't need to add this yourself, the important part is the conditional invocation of different react components from index.js. For this manifest.json the src/index.js would contain code to run in the background and a content script conditional run depending on context run from.

if (document.isBackground) {
  // some background script
} else if (document.isContentScripts) {
  // content script
  ReactDOM.render(
    <React.StrictMode>
      <App />
    </React.StrictMode>,
    document.getElementById("root")
  );
}