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

@devvai/devv-tagger-plugin

v1.0.0

Published

Vite/Webpack plugin to add source location attributes to JSX elements

Downloads

216

Readme

Vite Plugin Devv Tagger

为 React 组件自动添加调试标记的 Vite 插件。

功能特性

  • 🏷️ 自动为 JSX 元素添加调试标记属性
  • 🎯 精确定位组件源码位置(文件路径、行号、列号)
  • 🚀 零配置开箱即用
  • 🎨 支持 TypeScript 和 JSX
  • 🔧 可配置的标记选项
  • 🏗️ 生产环境自动禁用
  • 📊 构建统计信息输出
  • 🎭 智能排除 Fragment 和 Three.js 组件

安装

npm install vite-plugin-devv-tagger --save-dev
# 或
yarn add vite-plugin-devv-tagger -D
# 或
pnpm add vite-plugin-devv-tagger -D

使用方法

基础用法

vite.config.ts 中配置:

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import componentTagger from 'vite-plugin-devv-tagger';

export default defineConfig({
  plugins: [
    componentTagger(),  // 添加在 react 插件之前
    react(),
  ],
});

高级配置

import componentTagger from 'vite-plugin-devv-tagger';

export default defineConfig({
  plugins: [
    componentTagger({
      // 是否启用插件
      enabled: true,
      
      // 是否在生产环境中启用
      enableInProduction: false,
      
      // 要排除的文件路径模式
      exclude: ['node_modules', 'tests'],
      
      // 要处理的文件扩展名
      extensions: ['.jsx', '.tsx'],
      
      // 数据属性前缀
      prefix: 'data-devv',
      
      // 是否添加传统属性(兼容旧版本)
      includeLegacyAttributes: true,
    }),
    react(),
  ],
});

效果示例

输入代码

function App() {
  return (
    <div className="container">
      <h1>Hello World</h1>
      <button onClick={handleClick}>
        Click me
      </button>
    </div>
  );
}

输出代码(开发环境)

function App() {
  return (
    <div data-devv-id="src/App.tsx:3:4" data-devv-name="div" className="container">
      <h1 data-devv-id="src/App.tsx:4:6" data-devv-name="h1">Hello World</h1>
      <button data-devv-id="src/App.tsx:5:6" data-devv-name="button" onClick={handleClick}>
        Click me
      </button>
    </div>
  );
}

环境变量控制

通过环境变量控制插件行为:

# 开发环境(添加标记)
npm run dev

# 生产构建(不添加标记)
IS_PROD=true npm run build

# 开发环境也不添加标记
IS_PROD=true npm run dev

配置选项

| 选项 | 类型 | 默认值 | 描述 | |------|------|--------|------| | enabled | boolean | true | 是否启用插件 | | enableInProduction | boolean | false | 是否在生产环境中启用 | | exclude | string[] | ['node_modules'] | 要排除的文件路径模式 | | extensions | string[] | ['.jsx', '.tsx'] | 要处理的文件扩展名 | | prefix | string | 'data-devv' | 数据属性前缀 | | includeLegacyAttributes | boolean | true | 是否添加传统属性 |

排除的元素

插件会自动排除以下元素:

  • React Fragment
  • Three.js/React Three Fiber 组件
  • @react-three/drei 导入的组件

构建统计

构建完成后会输出统计信息:

[devv-tagger] 构建统计:
  - 总文件数: 45
  - 处理文件数: 32
  - 标记元素数: 256

开发提示

  1. 插件在 enforce: "pre" 模式下运行,确保在其他插件之前处理代码
  2. 使用 AST 解析确保准确识别 JSX 结构
  3. 自动生成 Source Map 支持调试
  4. 标记信息包含文件路径、行号、列号,方便精确定位

License

MIT