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 🙏

© 2025 – Pkg Stats / Ryan Hefner

vite-plugin-tcos

v1.0.0

Published

A Vite plugin for integrating with COS (Cloud Object Storage).

Readme

vite-plugin-cos

npm version npm license

一个用于 Vite 的插件,可将构建后的静态资源自动上传到腾讯云对象存储(COS)。

功能

  • 构建完成后自动上传资源到腾讯云 COS。
  • 支持通过 includeexclude 正则表达式过滤文件。
  • 支持 gzip 压缩,并自动设置 Content-Encoding
  • 支持上传失败自动重试。
  • 支持检查远端文件是否存在,避免重复上传。
  • 支持上传后删除本地文件。

安装

npm install vite-plugin-tcos --save-dev

使用

vite.config.ts 中引入并使用插件:

import { defineConfig } from 'vite';
import { ViteCOS } from 'vite-plugin-tcos';

export default defineConfig({
  plugins: [
    ViteCOS({
      // 必填项
      cosOptions: {
        SecretId: 'your-secret-id', // 推荐使用环境变量获取
        SecretKey: 'your-secret-key', // 推荐使用环境变量获取
        Bucket: 'your-bucket-appid',
        Region: 'your-region',
      },
      // 必填项
      project: 'my-project/v1',

      // 可选项
      cosBaseDir: 'vite-assets',
      exclude: /\.html$/,
      enableLog: true,
      gzip: true,
      removeMode: false,
    }),
  ],
});

注意: 为了安全起见,强烈建议通过环境变量(例如 process.env.COS_SECRET_ID)来传递 SecretIdSecretKey,而不是直接硬编码在配置文件中。

配置选项

| 属性 | 类型 | 是否必填 | 默认值 | 描述 | | :--------------------- | :-------- | :------- | :-------------- | :--------------------------------------------------------------- | | cosOptions | object | | - | 腾讯云 COS 的配置,与 cos-nodejs-sdk-v5 的构造函数参数一致。 | | cosOptions.SecretId | string | | - | 腾讯云 API 密钥 ID。 | | cosOptions.SecretKey | string | | - | 腾讯云 API 密钥 Key。 | | cosOptions.Bucket | string | | - | COS 存储桶名称,格式为 BucketName-APPID。 | | cosOptions.Region | string | | - | COS 存储桶所在地域。 | | project | string | | - | 项目标识,会作为上传路径的一部分。 | | cosBaseDir | string | 否 | 'vite-assets' | 在 COS 上的基础目录,最终上传路径为 cosBaseDir/project。 | | include | RegExp | 否 | undefined | 包含文件的正则表达式,默认为全部文件。 | | exclude | RegExp | 否 | undefined | 排除文件的正则表达式,默认不排除任何文件。 | | retry | number | 否 | 3 | 上传失败时的重试次数。 | | existCheck | boolean | 否 | true | 上传前是否检查远端文件是否存在,若存在则跳过。 | | gzip | boolean | 否 | false | 是否对文件进行 Gzip 压缩,并添加 Content-Encoding: gzip 头部。 | | removeMode | boolean | 否 | false | 上传成功后是否删除本地的对应文件。 | | enableLog | boolean | 否 | false | 是否在控制台打印详细日志。 | | ignoreError | boolean | 否 | false | 是否在上传出错时忽略错误并继续构建。 |