@froxz/vite-plugin-s3

中文文档
2.1.4发布于 2026/06/22MITTypeScriptES Module构建来源已验证近 30 天下载 6.7万

Allows you to upload files to AWS S3 or any other S3 compatible provider

原始使用文档
文档目录7 节
  1. 🚀 Features
  2. 📦 Install
  3. 🦄 Usage
  4. 👀 Options
  5. 💧 DigitalOcean Spaces Object Storage example
  6. 🙏 Thanks
  7. 📄 License

vite-plugin-s3

S3 compatible file uploader Plugin for Vite

vite-plugin-s3 banner

Version NPM Downloads GitHub License OSSF-Scorecard Score

🚀 Features

  • 🦾 Type Strong: written in TypeScript
  • ⚡ S3 Compatible: Support any S3 compatible provider (AWS, DO Spaces...)
  • ✨ Uploads any files: can upload any files or directory not just build folder

📦 Install

$ npm i @froxz/vite-plugin-s3

🦄 Usage

uploadOptions default to ACL: 'public-read' so you may need to override if you have other needs.

Add vite-plugin-s3 plugin to vite.config.js / vite.config.ts and configure it:

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'
      }
    })
  ]
})

👀 Options

enabled/disable: This setting can be used to disable or enable the uploading of assets (In addition Plugin is disabled in SSR and non build run)

OptionDescriptionTypeDefault
excludeA Pattern to match for excluded contentstring,RegExp,Function,Arraynull
includeA Pattern to match for included contentstring,RegExp,Function,Arraynull
clientConfigThe configuration interface of S3Client class constructorS3ClientConfigrequired
uploadOptionsPutObjectRequest options except Body and KeyPutObjectRequestrequired
basePathNamespace of uploaded files on S3stringnull
directoryDirectory to uploadstringbuild.outDir
sequentialUploadsIf true, files will be uploaded sequentially.booleanfalse

Advanced include and exclude rules

include and exclude in addition to a RegExp you can pass a function which will be called with the path as its first argument. Returning a truthy value will match the rule. You can also pass an Array of rules, all of which must pass for the file to be included or excluded.

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'
            }
        })
    ]
})

💧 DigitalOcean Spaces Object Storage example

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'
            }
        })
    ]
})

🙏 Thanks

Thanks to MikaAK for s3-plugin-webpack used as inspiration fro this plugin

📄 License

MIT License Sergkei Melingk

DigitalOcean Referral Badge

版本与发布记录

@froxz/vite-plugin-s3 共发布 36 个版本,首次发布于 2023/03/14;过去 12 个月发布了 5 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.1.4latest2026/06/224 个月前
2.1.32026/06/155 个月前
2.1.22026/06/035 个月前
2.1.12026/06/025 个月前
2.1.02026/06/025 个月前
2.0.52025/07/281.3 年前

关于 @froxz/vite-plugin-s3 的常见问题

@froxz/vite-plugin-s3 是什么?

Allows you to upload files to AWS S3 or any other S3 compatible provider

如何安装 @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 和提交记录判断。