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 🙏

© 2025 – Pkg Stats / Ryan Hefner

babel-plugin-react-component-auto-labeler

v1.0.4

Published

A Babel plugin that adds data attributes to React components with their name

Readme

babel-plugin-react-component-auto-labeler

A Babel plugin that automatically adds a data-component-name attribute to the top-level JSX element of your React function components — ideal for debugging, testing, or traceability in devtools.

Supports Vite, Next.js, and any toolchain that uses Babel.


✨ Features

  • Adds data-component-name="MyComponent" automatically
  • No manual annotation required
  • Zero-op in production if disabled
  • Useful for visual debugging and test selectors

⚒️ Installation

npm install --save-dev babel-plugin-react-component-auto-labeler

Or with Yarn:

yarn add -D babel-plugin-react-component-auto-labeler

🔧 Setup

➤ Vite (with @vitejs/plugin-react)

// vite.config.ts
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import autoLabeler from "babel-plugin-react-component-auto-labeler";

export default defineConfig(({ mode }) => {
  const isDev = mode === "development";

  return {
    plugins: [
      react({
        babel: {
          plugins: [[autoLabeler, { enabled: isDev }]],
        },
      }),
    ],
  };
});

Make sure your plugin is compiled as ESM and your project uses "type": "module" in package.json.


🏷️ What it does

✅ Input:

export const MyCard = () => <section className="card">Hello</section>;

✅ Output (after plugin runs):

<section class="card" data-component-name="MyCard">
  Hello
</section>

Example

If you have the following component:

export const TestButton = ({ text }: { text: string }) => {
  return <button>{text}</button>;
};

And you look into the DOM, it will show something like this:

Before the use of this plugin, the button has no identifier.

Now, this can be easily mitigated by using React Dev Tools, which will give you the component name. But, if you don't want to swap between the two debug-views, this plugin, once setup as described above, will show the following:

After we use the plugin, it has an identifier.

(Notice how both the app div and the button now shows their names.)


⚙️ Options

| Option | Type | Default | Description | | --------------- | ------- | ----------------------- | -------------------------------------------------- | | enabled | boolean | true | Enables/disables the plugin (e.g., in production) | | attributeName | string | "data-component-name" | The name of the attribute to add on each component |

You can disable it dynamically:

[autoLabeler, { enabled: process.env.NODE_ENV === "development" }];

Development

If you want to help me add features or fix a bug, you just:

  • get the code from github
  • install the dependencies (npm i)
  • Make your changes
  • Build the package (npm run build)
  • (optional) Package the package (npm pack) and test it in another project locally (npm install ../path/to/package)
  • Put up a PR with your changes
    • Avoid cursing, personal attacks, hate crimes and/or public support of the Dutch in your description
  • Get a good review and get it merged

🌍 Use cases

  • Quickly identify components in browser devtools
  • Add selectors for E2E/integration testing ([data-component-name="MyButton"])
  • Track usage of shared or critical components
  • Build your own dev tools / analytics

📜 License

MIT © Morkalork