
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
@zippybee/plugin-component-name
Advanced tools
一个为 Vue3 组件自动注入组件名称的 Vite 插件。
✨ 自动组件命名 - 根据文件路径自动生成组件名称
🎯 智能路由识别 - 只处理符合规则的路由组件
🔧 灵活配置 - 支持自定义命名规则和路径匹配
🚀 多框架支持 - 支持 Vue 3 (<script setup>) 和 React (JSX/TSX)
💾 缓存优化 - 内置命名转换缓存,提升性能
zippybee-plugin-comname/
├── package.json # 项目配置和依赖
├── tsconfig.json # TypeScript 编译配置
├── src/
│ ├── index.ts # 插件主入口,导出 Vite 插件
│ └── tool.ts # 工具函数和类型定义
└── README.md # 项目文档
npm install @zippybee/plugin-component-name -D
在 vite.config.ts 中引入插件:
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { zippyInjectComponetName } from "@zippybee/plugin-component-name";
export default defineConfig({
plugins: [
zippyInjectComponetName({
VIEW_PATH_PATTERN: /src\/views\/(.+\.(vue|tsx|jsx))$/,
PATH_SEPARATOR: "/",
MIN_DEPTH: 2,
MAX_DEPTH: 5,
}),
vue(),
],
});
如果需要自定义组件名称生成逻辑,可以传入 getName 函数:
zippyInjectComponetName({
VIEW_PATH_PATTERN: /src\/views\/(.+\.(vue|tsx|jsx))$/,
PATH_SEPARATOR: "/",
MIN_DEPTH: 2,
MAX_DEPTH: 5,
getName: (match, id) => {
// 自定义命名逻辑
const fullPath = match[1];
return customNameGenerator(fullPath);
},
});
zippyInjectComponetName(options: AutoNameOptions): Plugin创建 Vite 插件实例。
参数:
options - 插件配置选项返回值: Vite Plugin 对象
AutoNameOptions 接口继承自 RouteOption,扩展字段:
interface AutoNameOptions extends RouteOption {
getName?: (match: RegExpMatchArray, id: string) => string;
}
RouteOption 接口interface RouteOption {
// 用于匹配视图文件的正则表达式
VIEW_PATH_PATTERN: RegExp;
// 路径分隔符(通常为 '/' 或 '\\')
PATH_SEPARATOR: string;
// 最小路径深度
MIN_DEPTH: number;
// 最大路径深度
MAX_DEPTH: number;
}
插件通过以下逻辑生成组件名称:
MIN_DEPTH 和 MAX_DEPTH 范围内示例:
/src/views/user/profile/profile.vue
→ 路由路径: /user/profile
→ 组件名称: UserProfile
<script setup>)如果组件中已存在 defineOptions,插件会在其中注入 name 属性:
<script setup>
defineOptions({
name: "UserProfile",
});
</script>
如果不存在 defineOptions,插件会自动添加:
<script setup>
// ... 组件代码
defineOptions({ name: "UserProfile" });
</script>
defineComponent)插件会在 defineComponent 的配置对象中注入 name:
defineComponent({
name: "UserProfile",
// ... 其他配置
});
插件会在 defineComponent 中注入 name 属性:
const UserProfile = defineComponent({
name: "UserProfile",
// ... 其他配置
});
插件智能识别和跳过注释行,确保不会意外修改被注释的代码:
// 这一行会被跳过
// name: 'OldName'
name: "NewName"; // 这一行会被修改
enforce: 'pre' 确保在其他插件之前运行npm run build
编译后的文件输出到 dist/ 目录。
ISC
FAQs
一个为 Vue3 组件自动注入组件名称的 Vite 插件。
We found that @zippybee/plugin-component-name demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.