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 🙏

© 2026 – Pkg Stats / Ryan Hefner

vite-plugin-vue-component-name-custom

v1.0.0

Published

A Vite plugin for automatically injecting Vue component names based on file paths

Readme

vite-plugin-vue-component-name-custom

一个用于 Vue3 项目的 Vite 插件,可以根据组件路径自动注入组件名称。

特性

  • 🚀 自动为 Vue 组件注入 name 属性
  • 💪 支持 <script setup> 和普通 <script> 语法
  • 🎯 支持自定义组件名称生成规则
  • 📁 支持指定处理特定路径下的组件
  • 🚫 支持排除不需要处理的组件

安装

# npm
npm install vite-plugin-vue-component-name-custom -D

# pnpm
pnpm add vite-plugin-vue-component-name-custom -D

# yarn
yarn add vite-plugin-vue-component-name-custom -D

配置选项

getComponentName (已弃用,请使用 nameGenerator)

  • 类型: (file: string) => string
  • 必填: 否

nameGenerator

  • 类型: (filePath: string) => string
  • 必填: 否
  • 默认值: 内置的名称生成函数

用于自定义组件名称生成规则的函数,接收文件路径作为参数,返回组件名称。如果不提供,将使用内置的名称生成规则。

include

  • 类型: string | RegExp | (string | RegExp)[]
  • 必填: 否
  • 默认值: /\.vue$/

指定需要处理的文件。可以是字符串、正则表达式或它们的数组。

exclude

  • 类型: string | RegExp | (string | RegExp)[]
  • 必填: 否
  • 默认值: undefined

指定需要排除的文件。可以是字符串、正则表达式或它们的数组。

高级用法

自定义组件名称生成规则

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueComponentNameCustom from 'vite-plugin-vue-component-name-custom'

export default defineConfig({
  plugins: [
    vue(),
    vueComponentNameCustom({
      // 自定义文件匹配规则
      include: /\.vue$/,
      exclude: /node_modules/,
      
      // 自定义组件名称生成规则
      nameGenerator: (filePath) => {
        // 示例:添加前缀
        const baseName = filePath.split('/').pop()?.replace('.vue', '') || ''
        return `My${baseName}`
      }
    })
  ]
})