vite-plugin-deploy-oss 3.3.1 → 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.
- package/README.md +137 -47
- package/dist/index.js +6 -5
- package/package.json +5 -5
- package/pnpm-workspace.yaml +2 -0
package/README.md
CHANGED
|
@@ -1,75 +1,130 @@
|
|
|
1
1
|
# vite-plugin-deploy-oss
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/vite-plugin-deploy-oss)
|
|
4
|
+
[](https://www.npmjs.com/package/vite-plugin-deploy-oss)
|
|
5
|
+
[](https://www.npmjs.com/package/vite-plugin-deploy-oss)
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
Upload Vite build artifacts to Aliyun OSS.
|
|
8
|
+
[](https://www.npmjs.com/package/vite-plugin-deploy-oss)
|
|
9
|
+
[](https://www.npmjs.com/package/vite-plugin-deploy-oss)
|
|
10
|
+
[](https://www.npmjs.com/package/vite-plugin-deploy-oss)
|
|
6
11
|
|
|
7
|
-
|
|
12
|
+
Upload Vite build artifacts to Aliyun OSS.
|
|
8
13
|
|
|
9
|
-
##
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
10
17
|
|
|
11
18
|
```bash
|
|
12
19
|
pnpm add vite-plugin-deploy-oss -D
|
|
13
20
|
```
|
|
14
21
|
|
|
15
|
-
##
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
pnpm run build:test:debug
|
|
19
|
-
```
|
|
22
|
+
## Quick Start
|
|
20
23
|
|
|
21
|
-
|
|
24
|
+
## Quick Start
|
|
22
25
|
|
|
23
|
-
|
|
26
|
+
It is recommended to control the deployment using environment variables to avoid accidental uploads during local builds.
|
|
27
|
+
It is recommended to control the deployment using environment variables to avoid accidental uploads during local builds.
|
|
24
28
|
|
|
25
29
|
```ts
|
|
26
30
|
// vite.config.ts
|
|
31
|
+
import { defineConfig } from 'vite'
|
|
27
32
|
import vitePluginDeployOss from 'vite-plugin-deploy-oss'
|
|
28
33
|
|
|
29
|
-
|
|
30
|
-
export default {
|
|
31
|
-
// ...existing code...
|
|
34
|
+
export default defineConfig({
|
|
32
35
|
plugins: [
|
|
33
|
-
// 在最后一个插件中使用
|
|
34
36
|
vitePluginDeployOss({
|
|
35
|
-
// 建议按环境变量开关上传,避免本地/CI误上传
|
|
36
37
|
open: process.env.DEPLOY_OSS === '1',
|
|
37
|
-
// 输出调试耗时信息,方便排查慢在哪里
|
|
38
|
-
debug: process.env.DEPLOY_OSS_DEBUG === '1',
|
|
39
|
-
// 终端实时动效进度面板(默认 true)
|
|
40
|
-
fancy: true,
|
|
41
|
-
|
|
42
|
-
accessKeyId: '***',
|
|
43
|
-
accessKeySecret: '***',
|
|
44
|
-
bucket: '***',
|
|
45
|
-
region: '***',
|
|
46
|
-
uploadDir: `H5/zz/test`,
|
|
47
|
-
skip: ['**/index.html'],
|
|
48
|
-
|
|
49
|
-
// 默认 true:有上传失败时抛错并让构建失败
|
|
50
|
-
failOnError: true,
|
|
51
38
|
|
|
52
|
-
|
|
53
|
-
|
|
39
|
+
accessKeyId: process.env.OSS_ACCESS_KEY_ID || '',
|
|
40
|
+
accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET || '',
|
|
41
|
+
bucket: process.env.OSS_BUCKET || '',
|
|
42
|
+
region: process.env.OSS_REGION || '',
|
|
54
43
|
|
|
55
|
-
|
|
56
|
-
configBase:
|
|
44
|
+
uploadDir: 'H5/demo/prod',
|
|
45
|
+
configBase: 'https://example.com/H5/demo/prod/',
|
|
46
|
+
|
|
47
|
+
manifest: true,
|
|
48
|
+
failOnError: true,
|
|
57
49
|
}),
|
|
58
50
|
],
|
|
59
|
-
}
|
|
51
|
+
})
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Run build and deploy:
|
|
55
|
+
Run build and deploy:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
DEPLOY_OSS=1 pnpm build
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Configuration
|
|
62
|
+
|
|
63
|
+
## Configuration
|
|
64
|
+
|
|
65
|
+
| Option | Default | Description |
|
|
66
|
+
| :---------------- | :---------------- | :--------------------------------------------------------------------------- |
|
|
67
|
+
| `open` | `true` | Whether to enable upload. Recommended to control with environment variables. |
|
|
68
|
+
| `accessKeyId` | - | OSS access key ID. |
|
|
69
|
+
| `accessKeySecret` | - | OSS access key secret. |
|
|
70
|
+
| `bucket` | - | OSS bucket name. |
|
|
71
|
+
| `region` | - | OSS region, e.g., `oss-cn-beijing`. |
|
|
72
|
+
| `uploadDir` | - | Target directory in OSS to upload files. |
|
|
73
|
+
| `configBase` | - | Modifies Vite's asset base path synchronously. |
|
|
74
|
+
| `skip` | `'**/index.html'` | Glob pattern for files to skip uploading. |
|
|
75
|
+
| `overwrite` | `true` | Whether to overwrite existing files on OSS with the same name. |
|
|
76
|
+
| `autoDelete` | `false` | Whether to delete local build files after successful upload. |
|
|
77
|
+
| `manifest` | `false` | Whether to generate and upload a build manifest file. |
|
|
78
|
+
| `failOnError` | `true` | Whether to abort the build process if upload fails. |
|
|
79
|
+
| `debug` | `false` | Whether to output time cost information for debugging. |
|
|
80
|
+
| `fancy` | `true` | Whether to display a styled terminal progress bar. |
|
|
81
|
+
|
|
82
|
+
## Important Behaviors
|
|
83
|
+
|
|
84
|
+
- If `open: true` and any of the required options (`accessKeyId`, `accessKeySecret`, `bucket`, `region`, or `uploadDir`) are missing, the build process will fail and terminate.
|
|
85
|
+
- When `manifest` is enabled, all built files are uploaded automatically, and local build files are retained.
|
|
86
|
+
- When `manifest` is enabled, `skip` defaults to an empty array and `autoDelete` is forced to `false`.
|
|
87
|
+
- `oss-manifest.json` only tracks successfully uploaded files in the current build and does not include the manifest file itself.
|
|
88
|
+
- `configBase` affects both Vite's output asset paths and the URL addresses inside the manifest.
|
|
89
|
+
- `alias` only affects the URLs generated inside the manifest; it does not change the actual upload destination on OSS.
|
|
90
|
+
|
|
91
|
+
## Important Behaviors
|
|
92
|
+
|
|
93
|
+
- If `open: true` and any of the required options (`accessKeyId`, `accessKeySecret`, `bucket`, `region`, or `uploadDir`) are missing, the build process will fail and terminate.
|
|
94
|
+
- When `manifest` is enabled, all built files are uploaded automatically, and local build files are retained.
|
|
95
|
+
- When `manifest` is enabled, `skip` defaults to an empty array and `autoDelete` is forced to `false`.
|
|
96
|
+
- `oss-manifest.json` only tracks successfully uploaded files in the current build and does not include the manifest file itself.
|
|
97
|
+
- `configBase` affects both Vite's output asset paths and the URL addresses inside the manifest.
|
|
98
|
+
- `alias` only affects the URLs generated inside the manifest; it does not change the actual upload destination on OSS.
|
|
99
|
+
|
|
100
|
+
## Manifest
|
|
101
|
+
|
|
102
|
+
Enable manifest:
|
|
103
|
+
Enable manifest:
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
vitePluginDeployOss({
|
|
107
|
+
// ...other options
|
|
108
|
+
// ...other options
|
|
109
|
+
manifest: true,
|
|
110
|
+
})
|
|
60
111
|
```
|
|
61
112
|
|
|
62
|
-
|
|
113
|
+
Customize manifest filename:
|
|
114
|
+
Customize manifest filename:
|
|
63
115
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
116
|
+
```ts
|
|
117
|
+
vitePluginDeployOss({
|
|
118
|
+
// ...other options
|
|
119
|
+
// ...other options
|
|
120
|
+
manifest: {
|
|
121
|
+
fileName: 'meta/oss-manifest.json',
|
|
122
|
+
},
|
|
123
|
+
})
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Manifest JSON example:
|
|
127
|
+
Manifest JSON example:
|
|
73
128
|
|
|
74
129
|
```json
|
|
75
130
|
{
|
|
@@ -77,10 +132,45 @@ export default {
|
|
|
77
132
|
"files": [
|
|
78
133
|
{
|
|
79
134
|
"file": "assets/index-abc123.js",
|
|
80
|
-
"key": "H5/
|
|
81
|
-
"url": "https://
|
|
135
|
+
"key": "H5/demo/prod/assets/index-abc123.js",
|
|
136
|
+
"url": "https://example.com/H5/demo/prod/assets/index-abc123.js",
|
|
82
137
|
"md5": "d41d8cd98f00b204e9800998ecf8427e"
|
|
83
138
|
}
|
|
84
139
|
]
|
|
85
140
|
}
|
|
86
141
|
```
|
|
142
|
+
|
|
143
|
+
## Debugging
|
|
144
|
+
|
|
145
|
+
## Debugging
|
|
146
|
+
|
|
147
|
+
Enable `debug` to log the time taken for each key step during deployment, which helps locate bottlenecks:
|
|
148
|
+
Enable `debug` to log the time taken for each key step during deployment, which helps locate bottlenecks:
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
vitePluginDeployOss({
|
|
152
|
+
// ...other options
|
|
153
|
+
// ...other options
|
|
154
|
+
debug: process.env.DEPLOY_OSS_DEBUG === '1',
|
|
155
|
+
})
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
You can also run the playground command in the project:
|
|
159
|
+
You can also run the playground command in the project:
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
pnpm run build:test:debug
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Notes
|
|
166
|
+
|
|
167
|
+
## Notes
|
|
168
|
+
|
|
169
|
+
- It is highly recommended to use environment variables instead of hardcoding sensitive credentials.
|
|
170
|
+
- Keep `failOnError: true` for production builds to avoid completing the build/deployment pipeline when some files failed to upload.
|
|
171
|
+
- Make sure you do not need the local build directory before enabling `autoDelete`.
|
|
172
|
+
- The current version only supports ESM (`import` syntax). CommonJS (`require`) is not supported.
|
|
173
|
+
- It is highly recommended to use environment variables instead of hardcoding sensitive credentials.
|
|
174
|
+
- Keep `failOnError: true` for production builds to avoid completing the build/deployment pipeline when some files failed to upload.
|
|
175
|
+
- Make sure you do not need the local build directory before enabling `autoDelete`.
|
|
176
|
+
- The current version only supports ESM (`import` syntax). CommonJS (`require`) is not supported.
|
package/dist/index.js
CHANGED
|
@@ -262,6 +262,9 @@ function vitePluginDeployOss(option) {
|
|
|
262
262
|
const normalizedUploadDir = normalizePathSegments(uploadDir);
|
|
263
263
|
const normalizedConfigBase = configBase ? ensureTrailingSlash(normalizeUrlLikeBase(configBase)) : void 0;
|
|
264
264
|
const normalizedAlias = alias ? normalizeUrlLikeBase(alias) : void 0;
|
|
265
|
+
const manifestFileName = resolveManifestFileName(manifest);
|
|
266
|
+
const effectiveAutoDelete = manifestFileName ? false : autoDelete;
|
|
267
|
+
const effectiveSkip = manifestFileName ? [] : Array.isArray(skip) ? skip : [skip];
|
|
265
268
|
let buildFailed = false;
|
|
266
269
|
let upload = false;
|
|
267
270
|
let outDir = normalizePath(resolve2("dist"));
|
|
@@ -304,7 +307,7 @@ function vitePluginDeployOss(option) {
|
|
|
304
307
|
headers
|
|
305
308
|
});
|
|
306
309
|
if (result.res.status === 200) {
|
|
307
|
-
if (
|
|
310
|
+
if (effectiveAutoDelete) {
|
|
308
311
|
try {
|
|
309
312
|
await unlink(task.filePath);
|
|
310
313
|
} catch (error) {
|
|
@@ -505,9 +508,8 @@ function vitePluginDeployOss(option) {
|
|
|
505
508
|
if (!open || buildFailed) return;
|
|
506
509
|
const validationErrors = validateOptions();
|
|
507
510
|
if (validationErrors.length > 0) {
|
|
508
|
-
|
|
511
|
+
throw new Error(`vite-plugin-deploy-oss \u914D\u7F6E\u9519\u8BEF:
|
|
509
512
|
${validationErrors.map((err) => ` - ${err}`).join("\n")}`);
|
|
510
|
-
return;
|
|
511
513
|
}
|
|
512
514
|
upload = true;
|
|
513
515
|
config.base = normalizedConfigBase || config.base;
|
|
@@ -525,12 +527,11 @@ ${validationErrors.map((err) => ` - ${err}`).join("\n")}`);
|
|
|
525
527
|
const startTime = Date.now();
|
|
526
528
|
const debugEntries = [];
|
|
527
529
|
const client = new oss({ region, accessKeyId, accessKeySecret, secure, bucket, ...props });
|
|
528
|
-
const manifestFileName = resolveManifestFileName(manifest);
|
|
529
530
|
const collectFilesStartedAt = Date.now();
|
|
530
531
|
const files = globSync("**/*", {
|
|
531
532
|
cwd: outDir,
|
|
532
533
|
nodir: true,
|
|
533
|
-
ignore:
|
|
534
|
+
ignore: effectiveSkip
|
|
534
535
|
}).map((file) => normalizePath(file)).filter((file) => file !== manifestFileName);
|
|
535
536
|
debugEntries.push({
|
|
536
537
|
label: "\u626B\u63CF\u672C\u5730\u6587\u4EF6",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-deploy-oss",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
],
|
|
30
30
|
"author": "yulinzhao",
|
|
31
31
|
"license": "MIT",
|
|
32
|
-
"description": "
|
|
32
|
+
"description": "Upload Vite build artifacts to Aliyun OSS.",
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/ali-oss": "^6.23.3",
|
|
35
|
-
"@types/node": "^22.19.
|
|
35
|
+
"@types/node": "^22.19.19",
|
|
36
36
|
"prettier": "3.8.1",
|
|
37
37
|
"tsup": "^8.5.1",
|
|
38
38
|
"typescript": "^5.9.3"
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"ali-oss": "^6.23.0",
|
|
46
46
|
"chalk": "^5.6.2",
|
|
47
47
|
"cli-progress": "^3.12.0",
|
|
48
|
-
"cli-truncate": "^
|
|
48
|
+
"cli-truncate": "^6.0.0",
|
|
49
49
|
"glob": "^13.0.6",
|
|
50
50
|
"log-symbols": "^7.0.1",
|
|
51
|
-
"string-width": "^8.2.
|
|
51
|
+
"string-width": "^8.2.1"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"build": "tsup",
|