vite-plugin-walle-cos weekly downloads statistics
By choukin · npm · Webpack plugins
Upload Vite or Webpack production assets to Tencent COS
vite-plugin-walle-cos has 38 recorded weekly downloads on npm, an increase of 245% over the past 30 days, ranking #2840 of 3,247 tracked listings.
About vite-plugin-walle-cos
vite-plugin-walle-cos
将 Vite 或 Webpack 的生产构建资源上传到 Tencent COS,默认不上传 HTML。
支持范围
- Vite 2 - 7,支持 ESM 和 CommonJS 配置
- Webpack 4 / 5
- Node.js
>=12.22.0 <13或>=13.2.0(插件运行时;宿主构建工具另有版本要求) - 凭证来源:永久密钥、自定义
getAuthorization或临时密钥接口
插件运行时支持 Node.js >=12.22.0 <13 或 >=13.2.0(不支持 13.0.0–13.1.x);宿主构建工具也必须满足自身的 Node.js 版本要求。例如 Vite 3/4 要求 Node.js 14.18+,Vite 5/6 要求 Node.js 18+,Vite 7 要求 Node.js 20.19+ 或 22.12+。Node.js 12/13 已停止维护;如需使用,应确保宿主构建工具及依赖也支持对应版本。
安装
npm i -D vite-plugin-walle-cos
Vite
import { defineConfig } from 'vite'
import vitePluginWalleCOS from 'vite-plugin-walle-cos'
export default defineConfig({
base: 'https://static.example.com/app/',
plugins: [
vitePluginWalleCOS({
region: 'ap-beijing',
bucket: 'example-1234567890'
})
]
})
CommonJS 配置:
const vitePluginWalleCOS = require('vite-plugin-walle-cos')
Webpack 4 / 5
const WebpackPluginWalleCOS = require('vite-plugin-walle-cos/webpack')
module.exports = {
output: {
path: require('path').resolve(__dirname, 'dist'),
publicPath: 'https://static.example.com/app/'
},
plugins: [
new WebpackPluginWalleCOS({
region: 'ap-beijing',
bucket: 'example-1234567890'
})
]
}
工作方式
- Vite:插件只在
build时生效,于closeBundle阶段从磁盘扫描并上传build.outDir;相对路径按config.root解析,上传前缀取config.base。设置build.write: false时跳过上传,避免误传磁盘上残留的旧产物。vite build --watch的每轮重建都会触发closeBundle,因此 watch 构建整场跳过,并且只提示一次原因。 - Webpack:于
afterEmit阶段上传当前 compilation 的资源;outDir默认取output.path,base默认取output.publicPath;当 Webpack 未设置该项,或其值为auto/ 空字符串时,上传前缀默认为/。两者都可用插件参数覆盖。 - Webpack 触发条件:
enabled是唯一开关 ——false时不注册上传钩子,true(默认)时不管 Webpackmode是什么都会上传,development模式也不例外。唯一例外是 watch 编译(含 dev server):它会反复触发afterEmit,因此始终跳过并打印一次原因。 - Webpack 上传范围:只上传当前 compilation 声明的资源,不会重复上传
output.path中残留的旧文件。 - HTML 与忽略规则:默认忽略
**/*.html;SSR 客户端构建额外忽略ssr-manifest.json,SSR 服务端构建忽略全部文件。显式传入ignore会替换这些默认规则,而不是追加;例如ignore: []表示不忽略文件。 base/publicPath:接受完整的 HTTP(S) URL、//开头的协议相对地址(按https补全,//a.com这类没有路径的写法同样支持),或任意路径 / 相对前缀(如/assets/、assets/、correct-center、release:v2/)。相对前缀中冒号后带路径斜杠时按对象键前缀处理;已知的 URI scheme(如mailto:、file:、data:、https:cdn.example.com/a/)仍会拒绝。上传只依赖路径部分拼出 COS 对象键,域名仅用于日志里打印完整访问地址;没有域名时日志只显示对象键。路径中的百分号编码会解码为 COS 对象键,完整 URL 日志则保留 URL 编码。要改 COS 实际请求的域名,请用 SDK 的Domain配置,它和base互不影响。closeBundle顺序:Rollup 3 及以上使用顺序钩子,会等其他closeBundle写完后再上传。Rollup 2 不支持顺序钩子配置,只能使用函数钩子,因此不要依赖其他异步closeBundle生成的资源;无法探测 Rollup 版本时会告警并回退到这种模式。- 空构建:没有待上传文件时直接跳过,不创建 COS 客户端,也不输出上传开始/完成日志。
test: true:只打印目标路径,不创建 COS 客户端,也不需要可用凭证。
凭证
按以下顺序决定凭证来源:
| 优先级 | 条件 | 行为 |
|---|---|---|
| 1 | 显式配置 temporaryCredentials: { ... } | 使用临时密钥接口,必须提供 endpoint |
| 2 | 未显式配置临时密钥,但提供了 getAuthorization | 交给自定义回调,插件不请求临时密钥 |
| 3 | 未配置以上两项,且提供完整 Credentials 或同时提供 SecretId 和 SecretKey | 使用永久密钥 |
| 4 | 以上都没有 | 进入临时密钥模式,因缺少 endpoint 直接报错 |
补充说明:
Credentials中的secretId和secretKey必须同时提供;SDK 的Credentials优先于SecretId/SecretKey。SecretId/SecretKey也接受小写写法secretId/secretKey;两种写法同时存在时以大写为准。- 只提供
SecretId或SecretKey其中一个会直接报错。 temporaryCredentials: false关闭临时密钥逻辑。temporaryCredentials: true等价于启用临时密钥但不带任何配置,仍需通过temporaryCredentials: { endpoint }提供地址。
永久密钥
{
region: 'ap-beijing',
bucket: 'example-1234567890',
SecretId: process.env.COS_SECRET_ID,
SecretKey: process.env.COS_SECRET_KEY
}
临时密钥
临时密钥接口地址必须显式提供,不存在内置地址兜底;未提供时上传直接报错。
vitePluginWalleCOS({
region: 'ap-beijing',
bucket: 'example-1234567890',
temporaryCredentials: {
endpoint: 'https://gateway.example.com/cos/credential'
}
})
请求方法仅支持 GET(默认)和 POST,接口地址必须是 HTTP(S) URL。
默认识别以下响应结构(data 可嵌套最多 3 层):
{
code: '0',
data: {
tmpSecretId,
tmpSecretKey,
sessionToken,
startTime,
expiredTime
}
}
字段兼容如下,时间戳支持秒或毫秒(大于等于 1e12 视为毫秒):
| 字段 | 可接受的键名 | 说明 |
|---|---|---|
| 密钥 ID | TmpSecretId / tmpSecretId | 必填 |
| 密钥 Key | TmpSecretKey / tmpSecretKey | 必填 |
| 临时 Token | SecurityToken / sessionToken / XCosSecurityToken | 必填 |
| 生效时间 | StartTime / startTime | 缺省为当前时间前 1 秒 |
| 过期时间 | ExpiredTime / expiredTime | 必填,已过期直接报错 |
缓存与刷新行为:
- 到期前
refreshBeforeExpires(默认 60 秒)触发刷新,实际窗口取min(refreshBeforeExpires, 有效期 / 2),短寿命密钥不会被反复刷新。 - 并发上传复用同一个请求 Promise。
- 刷新失败时,只要缓存密钥仍未过期就继续使用,并在 1 - 5 秒内不重复重试;密钥已过期则报错。
- 接口报错会附带网关返回的
message/msg/error文本(截断到 200 字),便于定位。
请求方法、参数、请求头、请求体和超时都可以覆盖:
vitePluginWalleCOS({
region: 'ap-beijing',
bucket: 'example-1234567890',
temporaryCredentials: {
endpoint: 'https://gateway.example.com/cos/credential',
method: 'POST',
params: { channel: 'front-end' },
headers: { 'x-app-id': 'web' },
data: { scope: 'assets' },
timeout: 10000,
refreshBeforeExpires: 60
}
})
timeout 必须为正数;传入 0、负数或非法值会回退到默认的 10000 毫秒,避免构建在接口无响应时一直挂起。
如需复用 Axios、网关签名或其他请求封装,可传入 request:
import axios from 'axios'
const temporaryCredentials = {
endpoint: 'https://gateway.example.com/cos/credential',
method: 'GET',
params: { channel: 'example-channel' },
request: async ({ url, method, params, headers, data, timeout }) => {
const response = await axios({ url, method, params, headers, data, timeout })
return response.data
}
}
不同接口响应可通过 transformResponse 转为 SDK 所需字段:
temporaryCredentials: {
endpoint: 'https://gateway.example.com/cos/credential',
transformResponse(response) {
return {
TmpSecretId: response.result.id,
TmpSecretKey: response.result.key,
SecurityToken: response.result.token,
StartTime: response.result.start,
ExpiredTime: response.result.expires
}
}
}
自定义授权
已有网关或 STS 封装时,可以直接交给 COS SDK:…
Description from the npm listing.
- vite-plugin
- webpack-plugin
- walle-cos
- tencent
README badge
Show your rank in a README or on your website. The badge updates automatically.
Charts
Images: 30d · 1y · all time · 1600×900 dark
Adoption over time
7/30/90-day growth
Ranking history
Listing placement
Listing placement
Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.
Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.
Recent observations
Full history (135)Similar npm Webpack plugins plugins
All 20 vite-plugin-walle-cos alternativesData source
Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.
Listing: https://www.npmjs.com/package/vite-plugin-walle-cos. First seen Nov 16, 2026; last successful collection Dec 6, 2026. See the methodology.