# @froxz/vite-plugin-s3 中文文档

规范地址：https://npmcn.com/package/%40froxz/vite-plugin-s3/

版本：2\.1\.4
npm 元数据更新时间：2026-06-22T13:14:09.126Z
中文译文更新时间：2026-11-15T15:17:50.204Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40froxz/vite-plugin-s3
原文对照：https://npmcn.com/package/%40froxz/vite-plugin-s3/?lang=original
项目主页：https://github.com/SergkeiM/vite-plugin-s3
源码仓库：https://github.com/SergkeiM/vite-plugin-s3

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：26.3 kB，6 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：5 个
- peer 依赖：vite ^3\.1\.0 \|\| ^4\.0\.0 \|\| ^5\.0\.0 \|\| ^6\.0\.0 \|\| ^7\.0\.0 \|\| ^8\.0\.0
- 首次发布：2023-03-14T07:59:09.228Z
- 最新版本发布：2026-06-22T13:14:08.838Z
- 近 30 天下载量：67399（2026-10-16 至 2026-11-14，npm 官方下载统计）
- 已发布版本数：36（近 12 个月 5 个）

## 中文简介

允许您上传文件到 AWS S3 或任何其他 S3 兼容提供者

## 安装

```sh
npm install @froxz/vite-plugin-s3
```

也可以使用：`pnpm add @froxz/vite-plugin-s3`、`yarn add @froxz/vite-plugin-s3`、`bun add @froxz/vite-plugin-s3`

## README

# 紫外插图3

Vite 兼容文件上传插件

![vite-plugin-s3 banner](https://repository-images.githubusercontent.com/613344824/d377d1f4-94e5-49e9-a169-85e4b5653188)

[![Version](https://img.shields.io/npm/v/@froxz/vite-plugin-s3.svg?style=flat-square)](https://www.npmjs.com/package/@froxz/vite-plugin-s3) [![NPM Downloads](https://img.shields.io/npm/dm/%40froxz%2Fvite-plugin-s3?style=flat-square)](https://www.npmjs.com/package/@froxz/vite-plugin-s3) [![GitHub License](https://img.shields.io/github/license/SergkeiM/vite-plugin-s3?style=flat-square)](https://github.com/SergkeiM/vite-plugin-s3/blob/main/LICENSE) [![OSSF-Scorecard Score](https://img.shields.io/ossf-scorecard/github.com/SergkeiM/vite-plugin-s3?style=flat-square)](https://securityscorecards.dev/)

## \* 特性

-   🦾 **类型强**: 写入 [类型脚本](https://www.typescriptlang.org/)
-   ⚡ **S3 兼容性**: 支持任何 S3 兼容的提供者( AWS, DO Spaces...)
-   ✨ **上传任何文件**: 不仅可以构建文件夹,还可以上传任何文件或目录

## QQ 安装

```bash
$ npm i @froxz/vite-plugin-s3
```

## 使用量

> `uploadOptions` 默认为 `ACL: 'public-read'` 因此,如果你有其他需要,你可能需要推翻.

添加 `vite-plugin-s3` 插件为 `vite.config.js / vite.config.ts` 并配置它:

```ts
import { defineConfig } from 'vite'
import { ViteS3 } from '@froxz/vite-plugin-s3'

export default defineConfig({
  plugins: [
    ViteS3(!!process.env.UPLOAD_ENABLED, {
      basePath: '/build',
      clientConfig: {
        credentials: {
          accessKeyId: '',
          secretAccessKey: '',
        },
        region: 'eu-west-2'
      },
      uploadOptions: {
        Bucket: 'my-bucket'
      }
    })
  ]
})
```

## QQ 选项

> `enabled/disable`: 此设置可用于禁用或允许资产上传( 此外, SSR 中已禁用插件, 且非构建运行)

| 选项 | 说明 | 类型 | 默认 |
| :-- | :-- | :-- | :-- |
| `exclude` | 匹配被排除在外内容的模式 | `string,RegExp,Function,Array` | `null` |
| `include` | 匹配包含内容的模式 | `string,RegExp,Function,Array` | `null` |
| `clientConfig` | S3Client 类构建器的配置界面 | [S3 客户配置](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/s3clientconfig.html) | `required` |
| `uploadOptions` | `PutObjectRequest` 选项,但 `Body` 财务报告和审定财务报表 `Key` | [设置对象请求](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/putobjectrequest.html) | `required` |
| `basePath` | S3 上传文件的命名空间 | `string` | `null` |
| `directory` | 要上传的目录 | `string` | [构建。 出局 Dir](https://vitejs.dev/config/build-options.html#build-outdir) |
| `sequentialUploads` | 若为 `true`,文件将相继上传. | `boolean` | `false` |

#### 高级 `include` 财务报告和审定财务报表 `exclude rules`

`include` 财务报告和审定财务报表 `exclude` 除RegExp外,您还可以通过一个函数,该函数将以路径作为第一个参数。 返回一个真实值将符合规则。 您也可以通过一个规则阵列, 所有这些规则都必须通过才能包含或排除文件 .

```javascript
import { defineConfig } from 'vite'
import { ViteS3 } from '@froxz/vite-plugin-s3'
import isGitIgnored from 'is-gitignored'
// Up to you how to handle this
var isPathOkToUpload = function(path) {
    return require('my-projects-publishing-rules').checkFile(path)
}
export default defineConfig({
    plugins: [
        new ViteS3(!!process.env.UPLOAD_ENABLED, {
            // Only upload css and js and only the paths that our rules database allows
            include: [
                /.*\.(css|js)/,
                function(path) { isPathOkToUpload(path) }
            ],
            // function to check if the path is gitignored
            exclude: isGitIgnored,
            clientConfig: {
                credentials: {
                    accessKeyId: process.env.AWS_ACCESS_KEY_ID,
                    secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
                },
                region: 'eu-west-2'
            },
            uploadOptions: {
                Bucket: 'my-bucket'
            }
        })
    ]
})
```

## 💧 [数字海洋](https://m.do.co/c/1b7cfb2128b0) 空格对象存储示例

```javascript
import { defineConfig } from 'vite'
import { ViteS3 } from '@froxz/vite-plugin-s3'
export default defineConfig({
    plugins: [
        new ViteS3(!!process.env.UPLOAD_ENABLED, {
            clientConfig: {
                credentials: {
                    accessKeyId: process.env.DO_ACCESS_KEY_ID,
                    secretAccessKey: process.env.DO_SECRET_ACCESS_KEY,
                },
                endpoint: 'https://fra1.digitaloceanspaces.com',
                region: 'fra1'
            },
            uploadOptions: {
                Bucket: 'my-bucket'
            }
        })
    ]
})
```

## 谢谢

感谢 [米卡亚克](https://github.com/MikaAK) 页:1 [s3-插件-网络包装](https://github.com/MikaAK/s3-plugin-webpack) 用作启发fro 此插件

## 许可证

MIT 许可证 [塞尔克·梅林克](https://npmcn.com/package/%40froxz/vite-plugin-s3/LICENSE)

[![DigitalOcean Referral Badge](https://web-platforms.sfo2.digitaloceanspaces.com/WWW/Badge%202.svg)](https://www.digitalocean.com/?refcode=1b7cfb2128b0&utm_campaign=Referral_Invite&utm_medium=Referral_Program&utm_source=badge)

## 常见问题

### @froxz/vite-plugin-s3 是什么？

允许您上传文件到 AWS S3 或任何其他 S3 兼容提供者

### 如何安装 @froxz/vite-plugin-s3？

在项目目录运行 npm install @froxz/vite-plugin-s3，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：vite（^3\.1\.0 \|\| ^4\.0\.0 \|\| ^5\.0\.0 \|\| ^6\.0\.0 \|\| ^7\.0\.0 \|\| ^8\.0\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @froxz/vite-plugin-s3 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @froxz/vite-plugin-s3 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @froxz/vite-plugin-s3 可以商用吗？

@froxz/vite-plugin-s3 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @froxz/vite-plugin-s3 的下载量有多少？

根据 npm 官方下载统计，@froxz/vite-plugin-s3 在 2026/10/16 – 2026/11/14 这 30 天内被下载 67,399 次，日均约 2,247 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @froxz/vite-plugin-s3 还在维护吗？

最新版本 2\.1\.4 发布于 2026/06/22（4 个月前）；至今共发布 36 个版本，其中过去 12 个月发布了 5 个；首次发布于 2023/03/14。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

