@dhiwise/component-tagger

中文文档
1.0.16发布于 2026/07/29MITESM + CJS近 30 天下载 3.6万

Automatically annotate JSX components and HTML elements with data attributes

原始使用文档
文档目录7 节
  1. Installation
  2. Usage
  3. Vite
  4. Next.js
  5. HTML (CLI)
  6. Features
  7. License

@dhiwise/component-tagger

Automatically annotate JSX components and HTML elements with data attributes.

Installation

npm install @dhiwise/component-tagger

Usage

Vite

// vite.config.js
import { defineConfig } from 'vite';
import componentTagger from '@dhiwise/component-tagger';

export default defineConfig({
  plugins: [
    componentTagger({
      verbose: true,
      attributePrefix: 'data-component',
    }),
  ],
});

Next.js

// next.config.js
const componentTagger = require('@dhiwise/component-tagger/nextLoader');

module.exports = {
  webpack: (config) => {
    config.module.rules.push({
      test: /\.(js|jsx|ts|tsx)$/,
      use: [
        {
          loader: componentTagger,
          options: {
            verbose: true,
          },
        },
      ],
    });
    return config;
  },
};

HTML (CLI)

npx @dhiwise/component-tagger-html --output-dir public

Features

  • Automatically tags JSX components with data attributes
  • Supports Vite, Webpack, Next.js, and HTML
  • Configurable attribute prefixes and content extraction

License

MIT

版本与发布记录

@dhiwise/component-tagger 共发布 22 个版本,首次发布于 2025/04/09;过去 12 个月发布了 11 个版本。

版本发布日期距今
1.0.16latest2026/07/293 个月前
1.0.16-beta.1beta2026/07/233 个月前
1.0.16-beta.02026/05/255 个月前
1.0.152026/03/307 个月前
1.0.15-beta.02026/03/287 个月前
1.0.142025/12/1210 个月前

关于 @dhiwise/component-tagger 的常见问题

@dhiwise/component-tagger 是什么?

Automatically annotate JSX components and HTML elements with data attributes

如何安装 @dhiwise/component-tagger?

在项目目录运行 npm install @dhiwise/component-tagger,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:next(>=14.0.0)、vite(>=4.1.1)、webpack(>=5.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。它还提供命令行工具 component-tagger-html,可以用 npx component-tagger-html 直接运行。

@dhiwise/component-tagger 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/dhiwise__component-tagger 是否存在。

@dhiwise/component-tagger 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@dhiwise/component-tagger 可以商用吗?

@dhiwise/component-tagger 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dhiwise/component-tagger 的下载量有多少?

根据 npm 官方下载统计,@dhiwise/component-tagger 在 2026/10/12 – 2026/11/10 这 30 天内被下载 36,415 次,日均约 1,214 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dhiwise/component-tagger 还在维护吗?

最新版本 1.0.16 发布于 2026/07/29(3 个月前);至今共发布 22 个版本,其中过去 12 个月发布了 11 个;首次发布于 2025/04/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。