vite-plugin-deploy-ftp 3.4.0 → 3.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +99 -95
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,16 +1,20 @@
1
1
  # vite-plugin-deploy-ftp
2
2
 
3
- Vite 打包后的目录上传到 FTP,适合不想手动打开 FTP 工具、重复拖文件发布的项目。
3
+ Uploads the directory bundled by Vite to an FTP server. It is ideal for projects where you don't want to open FTP tools manually and repeatedly drag files to publish.
4
4
 
5
- ## 安装
5
+ [![npm version](https://img.shields.io/npm/v/vite-plugin-deploy-ftp.svg)](https://www.npmjs.com/package/vite-plugin-deploy-ftp)
6
+ [![npm downloads](https://img.shields.io/npm/dm/vite-plugin-deploy-ftp.svg)](https://www.npmjs.com/package/vite-plugin-deploy-ftp)
7
+ [![License](https://img.shields.io/npm/l/vite-plugin-deploy-ftp.svg)](https://github.com/yulin96/vite-plugin-deploy-ftp)
8
+
9
+ ## Installation
6
10
 
7
11
  ```bash
8
12
  pnpm add vite-plugin-deploy-ftp -D
9
13
  ```
10
14
 
11
- ## 快速开始
15
+ ## Quick Start
12
16
 
13
- 推荐用环境变量控制是否上传,默认本地普通打包不上传,只有明确开启时才发布。
17
+ It is recommended to control whether to upload using environment variables. By default, local builds will not trigger uploading, and publishing will only happen when explicitly enabled.
14
18
 
15
19
  ```bash
16
20
  # .env
@@ -52,7 +56,7 @@ export default defineConfig(({ mode }) => {
52
56
  })
53
57
  ```
54
58
 
55
- 上传时再打开开关:
59
+ Enable upload when building:
56
60
 
57
61
  ```bash
58
62
  # macOS / Linux
@@ -62,56 +66,56 @@ DEPLOY_FTP=1 pnpm build
62
66
  $env:DEPLOY_FTP='1'; pnpm build
63
67
  ```
64
68
 
65
- `FTP_PATH` 可以写一个目录:
69
+ `FTP_PATH` can be a single directory:
66
70
 
67
- ```bash
71
+ ```env
68
72
  FTP_PATH=/public_html
69
73
  ```
70
74
 
71
- 也可以写多个目录:
75
+ Or multiple directories separated by commas:
72
76
 
73
- ```bash
77
+ ```env
74
78
  FTP_PATH=/public_html,/backup_html
75
79
  ```
76
80
 
77
- ## 常用配置说明
78
-
79
- | 参数 | 说明 |
80
- | ----------------- | -------------------------------------------------------------- |
81
- | `open` | 是否启用上传。推荐用环境变量控制,避免普通打包时误上传。 |
82
- | `autoUpload` | 是否跳过“是否上传”的确认。自动发布时建议设为 `true`。 |
83
- | `failOnError` | 上传失败时是否让命令失败。发布流程里建议设为 `true`。 |
84
- | `uploadPath` | 上传目录。支持字符串,也支持字符串数组,数组会上传到多个目录。 |
85
- | `alias` | 访问域名。填写后,上传完成会输出可访问链接。 |
86
- | `singleBack` | 是否只备份指定文件。通常备份 `index.html` 就够,速度更快。 |
87
- | `singleBackFiles` | 单文件备份列表,支持子目录文件,例如 `assets/app.js`。 |
88
- | `ftps` | 多个 FTP 服务器配置。需要发布到多个服务器时使用。 |
89
- | `defaultFtp` | FTP 时默认选中的服务器名称,可减少手动选择。 |
90
- | `concurrency` | 同时上传的数量。服务器不稳定时保持默认值更稳。 |
91
-
92
- ## 重要行为说明
93
-
94
- - 插件只在 Vite 构建结束后上传。
95
- - `open: false` 时不会上传,也不会检查 FTP 配置。
96
- - `uploadPath` 传数组时,会把同一份文件依次上传到每个目录。
97
- - FTP 和多目录可以一起使用,会按“服务器 × 目录”的组合逐个上传。
98
- - 上传前如果远端目录已有文件,会根据配置询问或执行备份。
99
- - `singleBack: true` 时,只备份 `singleBackFiles` 里的文件。
100
- - `autoUpload: false` 时,上传前会询问是否继续。
101
- - 上传失败且 `failOnError: true` 时,构建命令会失败,方便发布系统拦截。
102
- - 当前版本仅支持 ESM,也就是 `import`,不支持 `require`。
103
-
104
- ## 风险提示
105
-
106
- - 不建议把 FTP 用户名、密码直接写进 `vite.config.ts`,推荐放到环境变量里。
107
- - 生产发布建议使用 `open` 环境变量开关,避免普通打包误传线上目录。
108
- - `uploadPath` 写成数组时,会上传到多个目录,请确认每个目录都是预期目标。
109
- - 完整备份会下载远端目录并重新上传压缩包,远端文件多时会比较慢。
110
- - 如果 FTP 服务器不稳定,不建议把 `concurrency` 调太高。
111
-
112
- ## 示例
113
-
114
- ### 多个 FTP 服务器
81
+ ## Configuration Guide
82
+
83
+ | Options | Description |
84
+ | :---------------- | :--------------------------------------------------------------------------------------------------------------------------------------- |
85
+ | `open` | Whether to enable upload. It is recommended to control this via environment variables to avoid accidental uploads during routine builds. |
86
+ | `autoUpload` | Skip the "confirm upload" prompt. Recommended to set to `true` for automated deployments. |
87
+ | `failOnError` | Whether to make the build command fail if the upload fails. Recommended to set to `true` in CI/CD pipelines. |
88
+ | `uploadPath` | Upload directory paths. Supports string or array of strings (files will be uploaded to all specified directories). |
89
+ | `alias` | Public URL / domain. If provided, the accessible URL will be printed after uploading. |
90
+ | `singleBack` | Whether to back up only specific files instead of the entire directory. Usually backing up `index.html` is enough and much faster. |
91
+ | `singleBackFiles` | List of files to back up in single-backup mode, supporting sub-directories, e.g., `assets/app.js`. |
92
+ | `ftps` | Multiple FTP configurations. Used when you need to publish to multiple servers. |
93
+ | `defaultFtp` | The default server name when configuring multiple FTPs to reduce manual selection. |
94
+ | `concurrency` | Number of simultaneous file uploads. Keep default if the server connection is unstable. |
95
+
96
+ ## Key Behaviors
97
+
98
+ - **Upload timing**: Uploads only after Vite finishes the build process.
99
+ - **Lazy evaluation**: When `open: false`, the plugin will not upload and will not validate FTP connection parameters.
100
+ - **Multiple paths**: When `uploadPath` is an array, the same build output will be uploaded sequentially to all specified paths.
101
+ - **Cross-product upload**: When combining multiple FTP servers and multiple paths, files are uploaded sequentially for every "Server × Directory" combination.
102
+ - **Backup before upload**: If the remote directory already contains files, the plugin will ask for confirmation or execute backups based on your configuration.
103
+ - **Selective backup**: When `singleBack: true` is configured, only files specified in `singleBackFiles` are backed up.
104
+ - **Manual confirmation**: When `autoUpload: false`, the plugin asks for manual confirmation in the CLI before proceeding.
105
+ - **Pipeline integration**: When `failOnError: true` and upload fails, the build command will exit with a non-zero code to block subsequent pipeline steps.
106
+ - **Module format**: This version only supports ESM (`import` syntax); `require` is not supported.
107
+
108
+ ## Risks & Best Practices
109
+
110
+ - **Security**: Do not hardcode FTP usernames and passwords in `vite.config.ts`. Always use environment variables.
111
+ - **Safety**: Ensure you control the production deployments via environment variables (like `open: process.env.DEPLOY_FTP === '1'`) to prevent local routine builds from overwriting production files.
112
+ - **Multiple Targets**: Ensure all paths listed in `uploadPath` are intended targets, especially when uploading to production environments.
113
+ - **Backup Speed**: Full backups require downloading the remote directory and uploading a zip archive back. This can be slow if the remote directory is large.
114
+ - **Rate Limits**: If the remote FTP server is unstable or rate-limited, do not set `concurrency` too high.
115
+
116
+ ## Examples
117
+
118
+ ### Multiple FTP Servers
115
119
 
116
120
  ```ts
117
121
  import vitePluginDeployFtp from 'vite-plugin-deploy-ftp'
@@ -146,7 +150,7 @@ export default {
146
150
  }
147
151
  ```
148
152
 
149
- ### 多个上传目录
153
+ ### Multiple Upload Directories
150
154
 
151
155
  ```ts
152
156
  import vitePluginDeployFtp from 'vite-plugin-deploy-ftp'
@@ -166,50 +170,50 @@ export default {
166
170
  }
167
171
  ```
168
172
 
169
- ## 完整配置表
170
-
171
- ### 通用参数
172
-
173
- | 参数 | 类型 | 默认值 | 说明 |
174
- | ----------------- | -------------------- | ---------------- | ------------------------------------------------ |
175
- | `open` | `boolean` | `true` | 是否启用插件 |
176
- | `uploadPath` | `string \| string[]` | - | FTP 服务器上的上传路径,传数组时会上传到多个目录 |
177
- | `singleBack` | `boolean` | `false` | 是否使用单文件备份模式 |
178
- | `singleBackFiles` | `string[]` | `['index.html']` | 单文件备份模式下要备份的文件列表 |
179
- | `debug` | `boolean` | `false` | 是否输出调试耗时 |
180
- | `maxRetries` | `number` | `3` | 连接或上传失败时的最大重试次数 |
181
- | `retryDelay` | `number` | `1000` | 重试延迟时间,单位毫秒 |
182
- | `showBackFile` | `boolean` | `false` | 是否显示备份文件列表 |
183
- | `autoUpload` | `boolean` | `false` | 是否跳过上传确认 |
184
- | `fancy` | `boolean` | `true` | 是否使用更丰富的终端输出 |
185
- | `failOnError` | `boolean` | `true` | 上传失败时是否中断构建命令 |
186
- | `concurrency` | `number` | `1` | 同时上传的任务数量 |
187
-
188
- ### 单个 FTP 配置参数
189
-
190
- | 参数 | 类型 | 默认值 | 说明 |
191
- | ---------- | -------- | ------ | -------------------------- |
192
- | `name` | `string` | - | FTP 配置名称 |
193
- | `host` | `string` | - | FTP 服务器地址 |
194
- | `port` | `number` | `21` | FTP 服务器端口 |
195
- | `user` | `string` | - | FTP 用户名 |
196
- | `password` | `string` | - | FTP 密码 |
197
- | `alias` | `string` | `''` | 网站别名,用于生成完整 URL |
198
-
199
- ### 多个 FTP 配置参数
200
-
201
- | 参数 | 类型 | 说明 |
202
- | ------------ | ------------- | ----------------------- |
203
- | `ftps` | `FtpConfig[]` | FTP 服务器配置数组 |
204
- | `defaultFtp` | `string` | 默认使用的 FTP 配置名称 |
205
-
206
- ### FtpConfig 对象
207
-
208
- | 参数 | 类型 | 默认值 | 说明 |
209
- | ---------- | -------- | ------ | ---------------------------------- |
210
- | `name` | `string` | - | FTP 服务器名称(用于选择界面显示) |
211
- | `host` | `string` | - | FTP 服务器地址 |
212
- | `port` | `number` | `21` | FTP 服务器端口 |
213
- | `user` | `string` | - | FTP 用户名 |
214
- | `password` | `string` | - | FTP 密码 |
215
- | `alias` | `string` | `''` | 网站别名,用于生成完整 URL |
173
+ ## Options Reference
174
+
175
+ ### General Options
176
+
177
+ | Options | Type | Default | Description |
178
+ | :---------------- | :------------------- | :--------------- | :--------------------------------------------------------------------------- |
179
+ | `open` | `boolean` | `true` | Enable or disable the plugin. |
180
+ | `uploadPath` | `string \| string[]` | - | FTP destination path(s). Array values will upload sequentially to all paths. |
181
+ | `singleBack` | `boolean` | `false` | Enable single file backup mode. |
182
+ | `singleBackFiles` | `string[]` | `['index.html']` | List of file paths to back up when `singleBack` is enabled. |
183
+ | `debug` | `boolean` | `false` | Enable verbose debug logs and duration metrics. |
184
+ | `maxRetries` | `number` | `3` | Maximum retry attempts for connection/upload failures. |
185
+ | `retryDelay` | `number` | `1000` | Delay between retry attempts (ms). |
186
+ | `showBackFile` | `boolean` | `false` | Print backup file list to the console. |
187
+ | `autoUpload` | `boolean` | `false` | Bypass CLI confirmation prompt before starting uploads. |
188
+ | `fancy` | `boolean` | `true` | Enable stylish console UI outputs. |
189
+ | `failOnError` | `boolean` | `true` | Throw errors to fail the Vite build command on upload failure. |
190
+ | `concurrency` | `number` | `1` | Number of simultaneous file uploads. |
191
+
192
+ ### Single FTP Configuration
193
+
194
+ | Options | Type | Default | Description |
195
+ | :--------- | :------- | :------ | :-------------------------------------------------------- |
196
+ | `name` | `string` | - | Identifier for the FTP configuration. |
197
+ | `host` | `string` | - | FTP host address. |
198
+ | `port` | `number` | `21` | FTP port. |
199
+ | `user` | `string` | - | FTP username. |
200
+ | `password` | `string` | - | FTP password. |
201
+ | `alias` | `string` | `''` | Public site URL alias used to format the final page link. |
202
+
203
+ ### Multiple FTP Configuration
204
+
205
+ | Options | Type | Description |
206
+ | :----------- | :------------ | :----------------------------------------------- |
207
+ | `ftps` | `FtpConfig[]` | List of FTP server configurations. |
208
+ | `defaultFtp` | `string` | Default FTP config name to select automatically. |
209
+
210
+ ### FtpConfig Object
211
+
212
+ | Options | Type | Default | Description |
213
+ | :--------- | :------- | :------ | :-------------------------------------------------------- |
214
+ | `name` | `string` | - | FTP configuration name (shown in selection prompt). |
215
+ | `host` | `string` | - | FTP host address. |
216
+ | `port` | `number` | `21` | FTP port. |
217
+ | `user` | `string` | - | FTP username. |
218
+ | `password` | `string` | - | FTP password. |
219
+ | `alias` | `string` | `''` | Public site URL alias used to format the final page link. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-deploy-ftp",
3
- "version": "3.4.0",
3
+ "version": "3.4.1",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",