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

vite-plugin-wegic-metadata

v0.1.2

Published

Vite 插件:为 JSX 元素注入 data-wegic-id 等元数据

Downloads

132

Readme

vite-plugin-wegic-metadata

为 JSX/TSX 元素自动注入元数据属性,用于实现类似 Lovable 的视觉编辑功能。

功能特性

  • 🎯 自动为 JSX 元素注入 data-wegic-id 等元数据属性
  • 📍 记录元素在源代码中的精确位置(文件路径、行号、列号)
  • 🔧 支持自定义配置(包含/排除文件、启用/禁用)
  • ⚡ 基于 Babel 的高效转换
  • 🎨 保持代码格式和行号不变

安装

pnpm install vite-plugin-wegic-metadata

使用

vite.config.ts 中添加插件:

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import wegicMetadata from 'vite-plugin-wegic-metadata';

export default defineConfig({
  plugins: [
    react(),
    wegicMetadata({
      enabled: true, // 是否启用,默认 true
      include: ['.tsx', '.jsx'], // 处理的文件扩展名
      exclude: ['node_modules'], // 排除的路径
    }),
  ],
});

注入的元数据属性

插件会为每个 JSX 元素添加以下属性:

<div
  data-wegic-id="src/components/Hero.tsx:12:8"
  data-wegic-name="div"
  data-component-path="src/components/Hero.tsx"
  data-component-line="12"
  data-component-file="Hero.tsx"
  data-component-name="div"
  data-component-content="%7B%22className%22%3A%22container%22%7D"
>
  内容
</div>

属性说明

  • data-wegic-id: 唯一标识符,格式为 文件路径:行号:列号
  • data-wegic-name: 元素标签名或组件名
  • data-component-path: 组件文件的相对路径
  • data-component-line: 元素在源代码中的行号
  • data-component-file: 文件名
  • data-component-name: 元素名称
  • data-component-content: URL 编码的元素属性内容(JSON 格式)

配置选项

interface WegicMetadataOptions {
  enabled?: boolean; // 是否启用,默认 true
  include?: string[]; // 处理的文件扩展名,默认 ['.tsx', '.jsx']
  exclude?: string[]; // 排除的路径模式,默认 ['node_modules']
  root?: string; // 项目根目录,默认 process.cwd()
}

工作原理

  1. 拦截 .tsx.jsx 文件的转换过程
  2. 使用 Babel 解析 JSX 代码生成 AST
  3. 遍历 AST,为每个 JSX 元素添加元数据属性
  4. 生成新的代码并保持原始格式

注意事项

  • 仅在开发环境下使用,生产环境建议禁用以减小包体积
  • 已有 data-wegic-id 属性的元素不会重复注入
  • Fragment 和特殊元素会被自动跳过

License

MIT