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

nextjs-tagger

v1.0.10

Published

A lightweight Babel plugin that automatically adds debug attributes to HTML elements in Next.js projects for easier AI-assisted development

Readme

nextjs-tagger

npm version License: MIT

A lightweight plugin that automatically adds debug attributes to HTML elements in Next.js projects for easier AI-assisted development.

Perfect for AI coding assistants, code navigation, and debugging! When you click on an element in the browser, you can quickly tell an AI exactly which file and line to modify.

🌟 Features

  • 🎯 Precise Code Location: Adds data-wb-id="file:line:column" to HTML elements
  • 🚀 Zero Runtime Cost: Only active in development mode
  • Lightweight: Minimal impact on build time
  • 🔧 Highly Configurable: Customize prefixes, file patterns, and more
  • 🎨 HTML Elements Only: Skips React components, focuses on DOM elements
  • 📦 Static Export Compatible: Works with output: 'export'
  • 🤖 AI-Friendly: Perfect for AI-assisted development workflows
  • Full Next.js Compatibility: Works with SWC, next/font, and Turbopack
  • 🚀 Turbopack Support: Full compatibility with Next.js Turbopack mode

📦 Installation

npm install --save-dev nextjs-tagger

or

yarn add -D nextjs-tagger

or

pnpm add -D nextjs-tagger

🚀 Quick Start

Next.js Plugin (Recommended)

1. Update your next.config.js:

const withNextjsTagger = require("nextjs-tagger/next");

/** @type {import('next').NextConfig} */
const nextConfig = {
  // Your existing config...
};

module.exports = withNextjsTagger({
  enabled: true,
  prefixName: "wb",
  debug: false,
})(nextConfig);

2. Restart your development server

3. Works with both standard mode and Turbopack:

# Standard mode
npm run dev

# Turbopack mode (also supported)
npm run dev -- --turbopack

Babel Plugin (Alternative)

1. Create or update .babelrc.js:

module.exports = {
  presets: ["next/babel"],
  plugins: [
    [
      "nextjs-tagger",
      {
        enabled: process.env.NODE_ENV === "development",
        prefixName: "wb",
        debug: false,
      },
    ],
  ],
};

2. Restart your development server

⚙️ Configuration Options

| Option | Type | Default | Description | | ------------ | ------------------------ | ---------------------------------------- | ------------------------------------------------------------------- | | enabled | boolean | process.env.NODE_ENV === 'development' | Whether to enable the plugin | | prefixName | string | 'wb' | Prefix for the debug attribute (will become data-{prefixName}-id) | | debug | boolean | false | Enable debug logging | | include | string[] | ['.tsx', '.jsx'] | File extensions to process | | exclude | string[] or RegExp[] | ['node_modules'] | File patterns or paths to exclude from processing |

🤖 AI Integration Example

Once installed, you can easily communicate with AI assistants:

🧑 "I want to modify the button at data-wb-id='components/Header.tsx:17:6'"

🤖 "I'll help you modify the button in components/Header.tsx at line 17, column 6"

The AI can instantly locate the exact file and position to make changes!

📱 Real-world Example

Before (original JSX):

export default function HomePage() {
  return (
    <div className='container'>
      <h1>Welcome to my site</h1>
      <button onClick={handleClick}>Click me</button>
    </div>
  );
}

After (with nextjs-tagger in development):

export default function HomePage() {
  return (
    <div className='container' data-wb-id='pages/index.tsx:3:4'>
      <h1 data-wb-id='pages/index.tsx:4:6'>Welcome to my site</h1>
      <button onClick={handleClick} data-wb-id='pages/index.tsx:5:6'>
        Click me
      </button>
    </div>
  );
}

🔄 Environment-based Configuration

Next.js Plugin

const withNextjsTagger = require("nextjs-tagger/next");

module.exports = withNextjsTagger({
  enabled: process.env.NODE_ENV === "development",
  prefixName: "wb",
  debug: process.env.NODE_ENV === "development",
})(nextConfig);

Babel Plugin

module.exports = {
  presets: ["next/babel"],
  plugins: [
    [
      "nextjs-tagger",
      {
        enabled: ["development", "staging"].includes(process.env.NODE_ENV),
        prefixName: "wb",
        debug: process.env.NODE_ENV === "development",
      },
    ],
  ],
};

🚫 What Gets Tagged

Tagged (HTML elements):

  • <div>, <span>, <button>, <input>, etc.
  • Any lowercase JSX element

Not Tagged:

  • React components (<MyComponent>)
  • Fragments (<> or <React.Fragment>)
  • Elements in node_modules

🛠 Troubleshooting

Plugin not working?

Next.js Plugin:

  1. Check next.config.js configuration
  2. Restart dev server
  3. Enable debug mode
  4. Check browser inspector for attributes

Babel Plugin:

  1. Check .babelrc.js exists in project root
  2. Restart dev server after config changes
  3. Enable debug mode: debug: true
  4. Check browser inspector for attributes

✅ Turbopack Support

The plugin now fully supports Next.js Turbopack mode! You can use it with or without the --turbopack flag:

# ✅ Both work now
next dev --turbopack
next dev

How it works: The plugin automatically detects and configures both webpack and Turbopack bundlers, ensuring seamless compatibility across all Next.js build modes.

TypeScript errors?

// Add to your global.d.ts or env.d.ts
declare namespace JSX {
  interface HTMLAttributes<T> {
    "data-wb-id"?: string;
  }
}

📊 Performance Impact

  • Development: Minimal impact, only processes JSX files
  • Production: Zero impact (disabled by default)
  • Bundle size: No runtime code added

🔧 Advanced Examples

Custom Attribute Names

// Will generate: custom-debug-id="file:line:col"
const withNextjsTagger = require("nextjs-tagger/next");
module.exports = withNextjsTagger({
  prefixName: "custom-debug",
})(nextConfig);

Multiple Environments

const withNextjsTagger = require("nextjs-tagger/next");

const isDev = process.env.NODE_ENV === "development";
const isStaging = process.env.NODE_ENV === "staging";

module.exports = withNextjsTagger({
  enabled: isDev || isStaging,
  prefixName: isDev ? "dev" : "staging",
  debug: isDev,
})(nextConfig);

Custom Exclude Patterns

const withNextjsTagger = require("nextjs-tagger/next");

module.exports = withNextjsTagger({
  enabled: true,
  prefixName: "wb",
  exclude: [
    /node_modules/, // RegExp pattern
  ],
})(nextConfig);

Static Export Compatibility

// next.config.js
const withNextjsTagger = require("nextjs-tagger/next");

module.exports = withNextjsTagger({
  enabled: true,
  prefixName: "wb",
})({
  output: "export",
  trailingSlash: true,
  images: {
    unoptimized: true,
  },
});

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

MIT © KanChaiShaoXia

🙏 Acknowledgments

  • Built with ❤️ for the AI-assisted development community
  • Inspired by the need for better code navigation tools
  • Special thanks to the Next.js, Babel, and SWC teams

Happy coding with AI! 🤖✨