紫外插图3
Vite 兼容文件上传插件
* 特性
- 🦾 类型强: 写入 类型脚本
- ⚡ S3 兼容性: 支持任何 S3 兼容的提供者( AWS, DO Spaces...)
- ✨ 上传任何文件: 不仅可以构建文件夹,还可以上传任何文件或目录
QQ 安装
$ npm i @froxz/vite-plugin-s3
使用量
uploadOptions默认为ACL: 'public-read'因此,如果你有其他需要,你可能需要推翻.
添加 vite-plugin-s3 插件为 vite.config.js / vite.config.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 客户配置 | required |
uploadOptions | PutObjectRequest 选项,但 Body 财务报告和审定财务报表 Key | 设置对象请求 | required |
basePath | S3 上传文件的命名空间 | string | null |
directory | 要上传的目录 | string | 构建。 出局 Dir |
sequentialUploads | 若为 true,文件将相继上传. | boolean | false |
高级 include 财务报告和审定财务报表 exclude rules
include 财务报告和审定财务报表 exclude 除RegExp外,您还可以通过一个函数,该函数将以路径作为第一个参数。 返回一个真实值将符合规则。 您也可以通过一个规则阵列, 所有这些规则都必须通过才能包含或排除文件 .
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'
}
})
]
})
💧 数字海洋 空格对象存储示例
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'
}
})
]
})
谢谢
感谢 米卡亚克 页:1 s3-插件-网络包装 用作启发fro 此插件
许可证
MIT 许可证 塞尔克·梅林克