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

@yiero/vite-plugin-scriptcat-backup

v1.0.2

Published

A vite plugin to backup script.

Readme

Vite Plugin ScriptCat Backup

English / 中文

功能

一个 Vite 插件,用于自动备份构建后的 ScriptCat(或 TamperMonkey)用户脚本。根据脚本版本号创建备份文件,避免重复备份同一版本。

安装

npm install vite-plugin-scriptcat-backup -D
# 或
yarn add vite-plugin-scriptcat-backup -D
# 或
pnpm add vite-plugin-scriptcat-backup -D

配置

| 参数 | 类型 | 描述 | 默认值 | |------|------|------|--------| | backupDir | string | 备份文件存储目录 | './backup' | | match | RegExp | 匹配需要备份的文件名正则表达式 | /\.js$/ | | scriptName | string | 脚本名称(用于生成备份文件名) | 当前目录名 |

使用

vite.config.js 中添加插件:

import { defineConfig } from 'vite'
import backupScriptPlugin from 'vite-plugin-scriptcat-backup'

export default defineConfig({
  plugins: [
    // 其他插件...
    
    backupScriptPlugin({
      backupDir: './script-backups',
      scriptName: 'my-script'
    })
  ]
})

与 vite-plugin-scriptcat-meta-banner 配合使用

本插件可以自动检测 vite-plugin-scriptcat-meta-banner 插件解析的脚本版本信息:

import { defineConfig } from 'vite'
import metaBannerPlugin from 'vite-plugin-scriptcat-meta-banner'
import backupScriptPlugin from 'vite-plugin-scriptcat-backup'

export default defineConfig({
  plugins: [
    metaBannerPlugin({
      // meta-banner 配置
    }),
    backupScriptPlugin()
  ]
})

工作原理

插件在构建过程中执行以下操作:

  1. 尝试从 vite-plugin-scriptcat-meta-banner 插件获取脚本版本信息
  2. 如果没有找到 meta-banner 插件,则从构建输出的脚本代码中提取 @version 元数据
  3. 根据脚本版本号检查是否已存在备份文件
  4. 如果备份文件已存在,则抛出 BackupExistError 错误
  5. 如果备份文件不存在,则将脚本代码保存到备份目录

备份文件命名格式:

<scriptName>_<version>.backup.js

例如:my-script_1.0.0.backup.js

错误处理

如果尝试备份已存在的脚本版本,插件会抛出 BackupExistError 错误,其中包含版本号信息:

try {
  // 构建过程
} catch (error) {
  if (error instanceof BackupExistError) {
    console.error(`版本 ${error.cause} 已备份,跳过备份操作`);
  }
}

贡献指南

欢迎贡献!请通过 GitHub 提交 issue 或 PR。

许可证

GPL-3 © AliubYiero