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 🙏

© 2026 – Pkg Stats / Ryan Hefner

component-tagger

v4.0.0

Published

A Vite plugin that automatically adds comprehensive component tagging attributes to JSX/TSX elements for debugging and testing

Readme

Component Tagger

A Vite plugin that automatically adds data-component-id attributes to JSX/TSX components for easier debugging and testing.

Features

  • 🏷️ Automatically adds component IDs to JSX elements
  • 📁 Configurable file path inclusion (filename or full path)
  • 🔢 Optional line number inclusion
  • 🎯 Smart component detection (uppercase = components, lowercase = DOM elements)
  • Development-only by default - no production overhead
  • 🔧 Customizable ID generation
  • 📝 TypeScript support

Installation

npm install --save-dev component-tagger

Setup

After installation, you need to configure the plugin in your Vite config:

npx component-tagger-setup

This will automatically add the plugin to your vite.config.ts file.

Usage

Basic Setup

After running npx component-tagger-setup, your vite.config.ts will look like this:

// vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { componentTagger } from 'component-tagger'

export default defineConfig({
  plugins: [
    react(),
    componentTagger() // Default settings: path, line, file (development only)
  ]
})

Custom Configuration

import { componentTagger } from 'component-tagger'

export default defineConfig({
  plugins: [
    react(),
    componentTagger({
      includeId: true,          // data-component-id="src/Button.tsx:15:4"
      includeName: false,       // data-component-name="Button" 
      includePath: true,        // data-component-path="src/Button.tsx"
      includeLine: true,        // data-component-line="15"
      includeFile: true,        // data-component-file="Button.tsx"
      includeContent: false,    // data-component-content="%7B...%7D"
      developmentOnly: true     // Only in development
    })
  ]
})

Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | includeId | boolean | true | Component ID (file:line:column) | | includeName | boolean | false | Element name (div, Button, etc.) | | includePath | boolean | true | File path | | includeLine | boolean | true | Line number | | includeFile | boolean | true | Filename | | includeContent | boolean | false | Props and content as JSON | | developmentOnly | boolean | true | Only add in development |

What It Does

The plugin adds customizable data attributes to JSX elements. By default, it adds attributes only in development mode (not in production builds):

  • data-component-id: File path with line and column (e.g., src/components/Button.tsx:15:4)
  • data-component-path: Full file path
  • data-component-line: Line number
  • data-component-file: Filename

Examples

Before Transformation

function MyComponent() {
  return (
    <div>
      <Header title="Hello World" />
      <MainContent>
        <Button onClick={handleClick}>Click me</Button>
      </MainContent>
    </div>
  )
}

After Transformation (Default Settings)

function MyComponent() {
  return (
    <div>
      <Header 
        data-component-id="src/MyComponent.tsx:4:6"
        data-component-path="src/MyComponent.tsx"
        data-component-line="4"
        data-component-file="MyComponent.tsx"
        title="Hello World" 
      />
      <MainContent 
        data-component-id="src/MyComponent.tsx:5:6"
        data-component-path="src/MyComponent.tsx"
        data-component-line="5"
        data-component-file="MyComponent.tsx"
      >
        <Button 
          data-component-id="src/MyComponent.tsx:6:8"
          data-component-path="src/MyComponent.tsx"
          data-component-line="6"
          data-component-file="MyComponent.tsx"
          onClick={handleClick}
        >
          Click me
        </Button>
      </MainContent>
    </div>
  )
}

With All Options Enabled

// componentTagger({ includeId: true, includeName: true, includePath: true, includeLine: true, includeFile: true, includeContent: true })

<Button 
  data-component-id="src/MyComponent.tsx:6:8"
  data-component-name="Button"
  data-component-path="src/MyComponent.tsx"
  data-component-line="6"
  data-component-file="MyComponent.tsx"
  data-component-content="%7B%22onClick%22%3A%22%5Bexpression%5D%22%2C%22text%22%3A%22Click%20me%22%7D"
  onClick={handleClick}
>
  Click me
</Button>

Uninstalling

When you're ready to remove Component Tagger, you need to run two commands:

  1. Remove from Vite config:
npx component-tagger-cleanup
  1. Uninstall the package:
npm uninstall component-tagger

The cleanup command will:

  • ✅ Remove the plugin from your vite.config.ts
  • ✅ Remove the import statement
  • ✅ Clean up your configuration

Use Cases

  • Debugging: Easily identify components in browser dev tools
  • Testing: Use component IDs for reliable E2E test selectors
  • Development: Quick component identification during development
  • Documentation: Generate component documentation with file references

Notes

  • Development only by default - won't add attributes in production builds
  • Only processes components (uppercase JSX elements), not DOM elements (lowercase)
  • Skips JSX fragments as they don't render as DOM elements
  • Automatically handles existing attributes to avoid duplicates
  • Works with TypeScript and modern JSX syntax
  • Supports complex component names (e.g., React.Component, styled.div)

License

MIT