UNPKG

vite-auto-deploy

Version:

用于配合 PHP 自动打包并上传打包后的文件到服务器指定目录的插件,此插件需要配合 php [项目地址](https://gitee.com/mxp131011/auto_deploy/)

166 lines (161 loc) 4.75 kB
import { Ora } from 'ora'; import { ResolvedConfig, PluginOption, Plugin } from 'vite'; import { BrotliOptions, ZlibOptions } from 'node:zlib'; type Algorithm = 'brotliCompress' | 'deflate' | 'deflateRaw' | 'gzip'; type CompressionOptions = Partial<BrotliOptions | ZlibOptions>; interface ViteCompressionConfig { /** * 是否在终端上输出压缩文件及其压缩比。 * @default true */ verbose?: boolean; /** * 文件最小需要达到多少才压缩,单位为字节 1kb 等于 1024 字节 * @default 1024 */ threshold?: number; /** * 压缩过滤器,仅压缩满足 正则表达式 或 方法返回true 的文件 * @default /\.(js|mjs|json|css|html)$/i */ filter?: RegExp | ((file: string) => boolean); /** * 是否禁用压缩 * @default false */ disable?: boolean; /** * 压缩算法 * @default gzip */ algorithm?: Algorithm; /** * 压缩后的文件格式 * @default .gz */ ext?: string; /** * 压缩配置 */ compressionOptions?: CompressionOptions; /** * 压缩后是否删除对应的源文件 * @default false */ deleteOriginFile?: boolean; /** * 自定义项目根目录 (源代码的根路径,非打包后的代码的根路径) */ root?: string; /** * 自定义需要打包上传的目录 (打包生成的代码的目录(可以是相对于源代码根路径的相对路径如(dist),也可以是绝对路径)) */ outDir?: string; /** * 压缩完成后的回调函数 */ success?: (config: ViteCompressionConfig, resolvedConfig?: ResolvedConfig | null) => void; } type CompressionInfo = { /** 压缩后文件大小 */ size: number; /** 源文件大小 */ oldSize: number; /**压缩后的完整路径 */ fullPath: string; }; type ViteAutoDeployConfig = { /** * 上传地址 */ uploadUrl: string; /** * 项目名称 (如果多个项目都是用的同上传地址时,服务端可用此字段区分是哪一个项目) */ projectName?: string; /** * 压缩后文件名称,注意不包含后缀名 * @default vite-auto-deploy */ zipName?: string; /** * 上传完成后,是否保留压缩包到本地 * @default false */ saveLocalZip?: boolean; /** * 公私匙保存的目录, * @default 系统登录账号下的根目录/.vite-auto-deploy/ */ saveSecretKeyDirectory?: string; /** * 加密私匙的密码, * @default vite-auto-deploy */ passphrase?: string; /** * 是否开启自动部署 * @default true */ autoDeploy?: boolean; /** * 自定义项目根目录 (源代码的根路径,非打包后的代码的根路径) */ root?: string; /** * 自定义需要打包上传的目录 (打包生成的代码的目录(可以是相对于源代码根路径的相对路径如(dist),也可以是绝对路径)) */ outDir?: string; /** * 上传需要携带的headers */ headers?: Record<string, string>; /** * 是否检查ssl(如https自签证书) 强烈不建议设置为true * @default false */ rejectUnauthorized?: boolean; /** * 是否重置密匙 ,注意设置为true每次打包都会重置密匙,建议重置一次后立即改为false * @default false */ resetKey?: boolean; /** * 控制是否输出错误日志 * @default false */ debug?: boolean; /** * 部署完成后的回调函数 */ success?: (config: ViteAutoDeployConfig, resolvedConfig?: ResolvedConfig | null) => void; }; type AutoDeployPostParam = { /** 项目名称 */ projectName: string; /** 密匙对ID */ keyPairId: string; /** 签名 */ sign: string; /** 时间戳 */ timestamp: number; }; /** * 自动化部署插件 * @param {object} config - 插件配置 */ declare function viteAutoDeployPlugin(config: ViteAutoDeployConfig): PluginOption; /** * 自动部署 */ declare function viteAutoDeply(config?: ViteAutoDeployConfig, viteConfig?: ResolvedConfig): Promise<boolean>; /** * 自动部署 */ declare function autoDeply(config: ViteAutoDeployConfig, outDir: string, spinner: Ora): Promise<boolean>; /** * 代码压缩插件 * @param {object} config - 插件配置 */ declare function viteCompressionPlugin(config?: ViteCompressionConfig): Plugin; export { type Algorithm, type AutoDeployPostParam, type CompressionInfo, type CompressionOptions, type ViteAutoDeployConfig, type ViteCompressionConfig, autoDeply, viteAutoDeployPlugin, viteAutoDeply, viteCompressionPlugin };