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

@arms/rum-vite-plugin

v1.1.1

Published

rum vite plugin

Readme

@arms/rum-vite-plugin

在 Vite 构建产物及其 SourceMap 中注入 ARMS RUM debugId,并在构建结束后自动将 SourceMap 上传到 ARMS RUM,用于线上 JS 错误的源码还原。

功能特性

  • 向每个 JS/CJS/MJS 产物注入 debugId 运行时代码,并同步写入对应 sourcemap 的 debugId 字段
  • 构建结束后自动调用云监控 OpenAPI GetRumSymbolFileParams 获取上传凭证并上传 sourcemap
  • 网络抖动、超时、限流与服务端 5xx 自动重试(指数退避 + 随机抖动,最多 3 次),鉴权/参数类 4xx 不重试
  • 受控并发上传,同进程内多个插件实例共享并发上限
  • strictUpload:上传失败时让构建失败,适合作为 CI 卡点
  • clearSourceMap:上传成功后删除本地 sourcemap,避免其随构建产物部署到线上

环境要求

  • Node.js 20 LTS 或 Node.js 22 及以上版本(依赖的 glob@^11 不支持 Node.js 18 与 21)
  • 运行时需支持 fetch、FormData、Blob
  • 必须开启 sourcemap 生成,且不能使用 inline 模式(见注意事项)

安装

npm install -D @arms/rum-vite-plugin

使用

import { defineConfig } from 'vite';
import { rumVitePlugin } from '@arms/rum-vite-plugin';

export default defineConfig({
  build: {
    sourcemap: true,
  },
  plugins: [
    rumVitePlugin({
      workspace: 'your-workspace',
      serviceId: 'your-rum-service-id',
      version: 'your-release-version',
      region: 'cn-hangzhou',
      accessKeyId: process.env.ALIBABA_CLOUD_ACCESS_KEY_ID,
      accessKeySecret: process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET,
      stsToken: process.env.ALIBABA_CLOUD_SECURITY_TOKEN, // 可选,STS 临时凭据
      clearSourceMap: true,
    }),
  ],
});

rumVitePlugin 接收 IUserOptions,在 vite build 时生效;vite dev(serve 模式)不会注入与上传。

配置项

| 字段 | 必填 | 默认值 | 说明 | | ----------------- | ---- | -------- | --------------------------------------------------------- | | workspace | 是 | - | ARMS RUM workspace | | serviceId | 是 | - | RUM 应用 Service ID | | version | 是 | - | 应用版本号,用于隔离不同发布版本的 sourcemap | | region | 是 | - | OpenAPI 区域,endpoint 为 cms.${region}.aliyuncs.com | | accessKeyId | 是 | - | 调用 ARMS OpenAPI 的 AccessKey ID | | accessKeySecret | 是 | - | 调用 ARMS OpenAPI 的 AccessKey Secret | | stsToken | 否 | - | 临时凭据 token,与临时 AK/SK 一起使用 | | endpoint | 否 | 生产域名 | 覆盖 CMS OpenAPI 域名,仅用于本地预发联调等测试场景 | | clearSourceMap | 否 | false | 上传成功后删除本地 sourcemap 文件 | | strictUpload | 否 | false | 上传失败时是否让构建失败;默认仅输出告警 | | concurrency | 否 | 4 | 并发上传的 sourcemap 文件数,取值 1-8,同进程内多实例共享 |

工作原理

  1. renderChunk 阶段向 JS 产物注入一小段 IIFE 代码:运行时它会把 debugId 以错误堆栈为 key 注册到 globalThis、window、self 等对象的 _armsRumDebugIds 上,RUM SDK 上报错误时据此取得 debugId;
  2. writeBundle 阶段扫描构建产物,定位每个 JS 对应的 .map 文件,并把同一个 debugId 写入 sourcemap JSON 的 debugId 字段;
  3. 调用 OpenAPI GetRumSymbolFileParams 获取上传地址与表单参数,再上传 sourcemap;
  4. 若开启 clearSourceMap,上传成功后删除本地 .map 文件。

若产物中已存在 Sentry 注入的 debugId(sentry-dbid-),插件会直接复用,不重复注入。

上传失败与重试

  • 网络抖动(ECONNRESET、fetch failed)、超时、限流(429 与阿里云 Throttling.* 错误码)及 5xx 会自动重试,最多尝试 3 次;每次重试都会重新申请上传凭证
  • 鉴权失败、参数错误等 4xx 业务错误不重试,直接记录失败
  • 取凭证请求超时为连接 10s、读取 30s;文件上传超时为 60s + 10s/MB,最长 5 分钟

构建结束时会输出汇总。默认情况下上传失败只打印告警、不阻断构建:

ARMS RUM WARN: Sourcemap upload finished: 7/9 succeeded, 2 failed.
ARMS RUM WARN: - /path/to/BaseLayout.10344805.js.map for fetch failed (caused by: ECONNRESET: read ECONNRESET)

如果希望上传失败时让构建失败,开启 strictUpload: true。此时抛出的错误会附带失败文件清单与原因,便于 CI 定位。

注意事项

  1. sourcemap 配置:使用 sourcemap: true 或 'hidden' 均可(插件会同时通过 sourceMappingURL 和 产物路径 + '.map' 两种方式定位);'inline' 不生成独立 .map 文件,无法上传。
  2. 文件大小:单个 sourcemap 文件不能超过 50 MiB,超限文件会被记录为上传失败(开启 strictUpload 时构建失败)。
  3. 凭据安全:AK/SK 建议通过环境变量或 CI 密钥管理注入,不要提交进仓库;临时凭据场景请同时传入临时 AK/SK 与 stsToken。
  4. 版本对应:每次发布请更新 version,并保证与 RUM 应用中登记的发布版本一致,避免不同版本的 sourcemap 混淆。
  5. 多实例共享并发:同进程注册多个插件实例时(如多页构建)共享同一并发上限;显式配置的 concurrency 可覆盖默认值,无法生效时会输出告警。
  6. 预发联调:仅测试场景传入 endpoint: 'cms-pre.cn-hangzhou.aliyuncs.com',不传时始终使用生产域名。
  7. 1.1.0 起不再支持 pid 回退和默认 version/region,升级前请显式补齐必填配置。

故障排查

| 现象 | 原因与处理 | | ----------------------------------------------------- | ------------------------------------------------------------------------------------------------- | | No source maps found for the bundle... | 未开启 sourcemap,或产物中没有 JS 文件;检查 build.sourcemap 配置 | | Sourcemap upload finished: x/y succeeded, z failed. | 存在失败文件,查看告警明细中的错误原因;网络类错误已自动重试过,仍失败多为凭据或环境问题 | | InvalidAccessKeyId.NotFound / 401 / 403 | AK/SK 或 stsToken 不正确、已失效,或当前账号无 GetRumSymbolFileParams 权限 | | File size is invalid | sourcemap 超过 50 MiB,需调整构建拆分或压缩 sourcemap | | 上传成功但错误无法还原源码 | 确认上传时使用的 version 与 RUM 应用中登记的发布版本一致;检查线上产物是否包含 debugId 注入代码 |

更多文档见仓库中的 USAGE.md 与 CHANGELOG.md。