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

@miraquai/vue-api-import-analyzer

v1.0.3

Published

分析 Vue/TS/JS 工程中从 `@/api/*` 导入的 API 函数,生成报告: - 普通模式:按文件/目录树分组 - 路由模式:按路由维度分组(自动解析路由组件与嵌套子组件) 可输出到控制台,也支持导出为 JSON 文件。

Downloads

6

Readme

vue-api-import-analyzer

分析 Vue/TS/JS 工程中从 @/api/* 导入的 API 函数,生成报告:

  • 普通模式:按文件/目录树分组
  • 路由模式:按路由维度分组(自动解析路由组件与嵌套子组件) 可输出到控制台,也支持导出为 JSON 文件。

限制:暂不支持默认导入(import foo from ...)和命名空间导入(import * as api from ...),当前仅支持具名导入(import { foo } from ...)。

安装

  • 全局安装后使用:
npm i -g @miraquai/vue-api-import-analyzer
analyze-apis <目标路径>
  • 项目内使用(本地依赖已安装时):
npx analyze-apis <目标路径>
  • 临时使用(无需安装到项目):
npx -p @miraquai/vue-api-import-analyzer analyze-apis <目标路径>

基本用法

analyze-apis <文件或目录>

示例:

# 分析单个文件并以文本输出
analyze-apis src/views/demo.vue --format text

# 分析整个 src 目录并以 JSON 输出(打印到控制台)
analyze-apis src --format json

# 分析并将结果导出为 JSON(默认写入到项目根目录 api-import-report.json)
analyze-apis src --output-json

# 分析并将结果导出到指定文件或目录
analyze-apis src --output-json reports/my-report.json
analyze-apis src --output-json reports/

路由模式

按路由入口(如 src/router/index.js)递归解析路由模块与组件;同时会广度遍历组件的相对/别名导入,统计嵌套子组件中的 API 使用。

用法:

# 仅打印 JSON(--router 模式默认只输出 JSON)
analyze-apis src/router/index.js --router

# 指定输出文件(两种写法)
analyze-apis src/router/index.js --router reports/router-apis.json
analyze-apis src/router/index.js --router --output-json reports/router-apis.json

路由模式 JSON 结构:

{
  "__router": true,
  "routes": [
    {
      "path": "/products",
      "name": "货品管理",
      "file": "src/pages/products/productList/index.vue",
      "dir": "src/pages/products/productList",
      "apis": [
        { "module": "@/api/goods", "imported": "getList", "local": "getList", "url": "/goods/list" }
      ]
    }
  ]
}

说明:路由名称优先取 meta.title,其次 meta.name,都没有时取路由对象外层 name

参数

  • --format: 输出格式,jsontext,默认 json
  • --alias-root: 别名根目录(如 src),默认 src
  • --alias-prefix: 路径别名前缀(不一定是 @),默认 @
  • --api-dir: API 目录名(相对别名根目录),默认 api
  • --options-file: 指定配置文件路径(支持 .cjs.json
  • --output-json [path]: 将结果导出为 JSON 文件
    • 不带路径:默认导出到项目根目录 api-import-report.json
    • 带目录路径:在该目录下生成 api-import-report.json
    • 带文件路径(以 .json 结尾):写入到该文件
  • --router [path]: 路由模式;可将输出路径直接跟在 --router 后作为简写(见“路由模式”示例)
  • --fetch-names name1,name2: 自定义请求函数名列表,逗号分隔(默认 fetch
  • -h/--help: 查看帮助

优先级:命令行参数 > 配置文件。

配置文件

程序会默认在项目根目录查找 vai.config.cjsvai.config.json

vai.config.cjs 示例:

module.exports = {
  aliasRoot: 'src',
  aliasPrefix: '@',
  apiDir: 'api',
  includeExt: ['.vue', '.ts', '.js', '.tsx', '.jsx'],
  ignoreDirs: ['node_modules', 'dist', 'build'],
  // 可选:自定义请求函数名列表(支持成员调用,如 request.post(...))
  fetchNames: ['fetch', 'request', 'axios']
}

vai.config.json 示例:

{
  "aliasRoot": "src",
  "aliasPrefix": "@",
  "apiDir": "api",
  "includeExt": [".vue", ".ts", ".js", ".tsx", ".jsx"],
  "ignoreDirs": ["node_modules", "dist", "build"],
  "fetchNames": ["fetch", "request", "axios"]
}

输出结构(JSON)

当目标为目录时,外层键为目标相对路径,内部为目录树;叶子节点(文件)对应一个数组,列出该文件中从 @/api/* 导入的具名导入:

{
  "src": {
    "views": {
      "demo.vue": [
        {
          "module": "@/api/user",
          "imported": "getUser",
          "local": "getUser",
          "url": "/api/user/info"
        }
      ]
    }
  }
}

字段说明:

  • module: 导入来源模块(如 @/api/user
  • imported: 具名导入的名称
  • local: 在当前文件中的本地名称(可能与 imported 相同或使用了 as 重命名)
  • url: 静态可解析到的请求 URL(仅当模块导出函数/变量体内包含静态 fetch(...)fetch.xxx(...) 或自定义的 name(...)/name.xxx(...),或在对象字面量中以 url 字段声明时可提取)

URL 解析增强(同文件内):

  • 常量与对象属性:const foo = '/x'; const map = { a: '/x' }
  • 常量别名:export const url = foo / export const url = map.a / map['a']
  • 对象入参:fetch({ url: map.a })

交互体验

  • 运行时在终端显示轻量“旋转帧”加载动画;分析结束后自动清除。

兼容性

  • Node.js >= 14
  • 默认别名为 @,别名根为 src,API 目录为 api;均可通过参数或配置文件覆盖

许可证

ISC