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

@ruan-cat/vite-plugin-ts-alias

v0.2.0

Published

将 tsconfig.paths 配置转换成 vite 的 alias 路径别名。

Readme

@ruan-cat/vite-plugin-ts-alias

npm version npm downloads

将 tsconfig.paths 配置转换成 vite 的 alias 路径别名。

[!CAUTION] 这个包是基于 Codpoe/vite-plugin-ts-alias 仓库的代码进行修改和增强的,不是作者原创的包

主要改进

  • ✅ 增加了更详细的错误提示
  • ✅ 优化了类型定义
  • ✅ 改进了错误处理机制

原始仓库Codpoe/vite-plugin-ts-alias

安装

npm install -D @ruan-cat/vite-plugin-ts-alias
# 或
yarn add -D @ruan-cat/vite-plugin-ts-alias
# 或
pnpm add -D @ruan-cat/vite-plugin-ts-alias

使用方法

基本用法

import { defineConfig } from "vite";
import { tsAlias } from "@ruan-cat/vite-plugin-ts-alias";

export default defineConfig({
	plugins: [tsAlias()],
});

自定义 tsconfig 文件名

import { defineConfig } from "vite";
import { tsAlias } from "@ruan-cat/vite-plugin-ts-alias";

export default defineConfig({
	plugins: [
		tsAlias({
			tsConfigName: "tsconfig.path.json",
		}),
	],
});

功能特性

  • 🔄 自动转换: 自动读取 tsconfig.json 中的 paths 配置并转换为 vite alias
  • 📁 路径解析: 支持相对路径和绝对路径的解析
  • 性能优化: 在 vite 构建的 pre 阶段执行,确保路径别名正确解析
  • 🛠️ 类型安全: 完整的 TypeScript 类型支持

配置说明

tsconfig.json 示例

{
	"compilerOptions": {
		"baseUrl": ".",
		"paths": {
			"@/*": ["src/*"],
			"@components/*": ["src/components/*"],
			"@utils/*": ["src/utils/*"]
		}
	}
}

转换结果

上述配置会被转换为以下 vite alias:

{
  "@": "/path/to/your/project/src",
  "@components": "/path/to/your/project/src/components",
  "@utils": "/path/to/your/project/src/utils"
}

API

tsAlias(options?)

参数

  • options (可选): 配置选项
    • tsConfigName (可选): tsconfig 文件名,默认为 'tsconfig.json'

返回值

返回一个 vite 插件对象。

注意事项

  1. 这是一个开发环境依赖,建议使用 -D 参数安装到 devDependencies
  2. 确保你的 tsconfig.json 中配置了 baseUrlpaths
  3. 插件会在 vite 的 pre 阶段执行,确保路径别名在构建开始前就被正确设置
  4. 如果找不到 tsconfig.json 或缺少必要的配置,插件会输出错误信息但不会中断构建

许可证

MIT