vite-plugin-deploy-oss 3.4.1 → 3.5.0
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 +84 -36
- package/dist/chunk-6D7VVVXN.js +728 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +156 -0
- package/dist/deploy-slMJUcSr.d.ts +70 -0
- package/dist/deploy.d.ts +2 -0
- package/dist/deploy.js +6 -0
- package/dist/index.d.ts +5 -54
- package/dist/index.js +19 -675
- package/package.json +16 -2
package/README.md
CHANGED
|
@@ -4,26 +4,16 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/vite-plugin-deploy-oss)
|
|
5
5
|
[](https://www.npmjs.com/package/vite-plugin-deploy-oss)
|
|
6
6
|
|
|
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)
|
|
11
|
-
|
|
12
7
|
Upload Vite build artifacts to Aliyun OSS.
|
|
13
8
|
|
|
14
9
|
## Installation
|
|
15
10
|
|
|
16
|
-
## Installation
|
|
17
|
-
|
|
18
11
|
```bash
|
|
19
12
|
pnpm add vite-plugin-deploy-oss -D
|
|
20
13
|
```
|
|
21
14
|
|
|
22
15
|
## Quick Start
|
|
23
16
|
|
|
24
|
-
## Quick Start
|
|
25
|
-
|
|
26
|
-
It is recommended to control the deployment using environment variables to avoid accidental uploads during local builds.
|
|
27
17
|
It is recommended to control the deployment using environment variables to avoid accidental uploads during local builds.
|
|
28
18
|
|
|
29
19
|
```ts
|
|
@@ -51,14 +41,69 @@ export default defineConfig({
|
|
|
51
41
|
})
|
|
52
42
|
```
|
|
53
43
|
|
|
54
|
-
Run build and deploy:
|
|
55
44
|
Run build and deploy:
|
|
56
45
|
|
|
57
46
|
```bash
|
|
58
47
|
DEPLOY_OSS=1 pnpm build
|
|
59
48
|
```
|
|
60
49
|
|
|
61
|
-
##
|
|
50
|
+
## Direct Upload
|
|
51
|
+
|
|
52
|
+
If you only want to upload an existing directory, use the built-in CLI. This does not require Vite.
|
|
53
|
+
|
|
54
|
+
Create a config file:
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
// deploy-oss.config.mjs
|
|
58
|
+
import { defineDeployConfig } from 'vite-plugin-deploy-oss'
|
|
59
|
+
|
|
60
|
+
export default defineDeployConfig({
|
|
61
|
+
accessKeyId: process.env.OSS_ACCESS_KEY_ID || '',
|
|
62
|
+
accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET || '',
|
|
63
|
+
bucket: process.env.OSS_BUCKET || '',
|
|
64
|
+
region: process.env.OSS_REGION || '',
|
|
65
|
+
|
|
66
|
+
outDir: 'dist',
|
|
67
|
+
uploadDir: 'H5/demo/prod',
|
|
68
|
+
configBase: 'https://example.com/H5/demo/prod/',
|
|
69
|
+
|
|
70
|
+
manifest: true,
|
|
71
|
+
failOnError: true,
|
|
72
|
+
})
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Run it from package scripts:
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"scripts": {
|
|
80
|
+
"deploy": "deploy-oss --config deploy-oss.config.mjs"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Or run it with npx:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npx vite-plugin-deploy-oss --config deploy-oss.config.mjs
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
You can also call the upload API directly:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import { deployOss } from 'vite-plugin-deploy-oss/deploy'
|
|
95
|
+
|
|
96
|
+
await deployOss({
|
|
97
|
+
accessKeyId: process.env.OSS_ACCESS_KEY_ID || '',
|
|
98
|
+
accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET || '',
|
|
99
|
+
bucket: process.env.OSS_BUCKET || '',
|
|
100
|
+
region: process.env.OSS_REGION || '',
|
|
101
|
+
outDir: 'dist',
|
|
102
|
+
uploadDir: 'H5/demo/prod',
|
|
103
|
+
})
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
`configBase` only changes URLs written to the manifest in direct upload mode. If you need Vite output paths to use the same base, keep using the Vite plugin during build.
|
|
62
107
|
|
|
63
108
|
## Configuration
|
|
64
109
|
|
|
@@ -69,6 +114,7 @@ DEPLOY_OSS=1 pnpm build
|
|
|
69
114
|
| `accessKeySecret` | - | OSS access key secret. |
|
|
70
115
|
| `bucket` | - | OSS bucket name. |
|
|
71
116
|
| `region` | - | OSS region, e.g., `oss-cn-beijing`. |
|
|
117
|
+
| `outDir` | `'dist'` | Local directory to upload when using CLI or direct API. |
|
|
72
118
|
| `uploadDir` | - | Target directory in OSS to upload files. |
|
|
73
119
|
| `configBase` | - | Modifies Vite's asset base path synchronously. |
|
|
74
120
|
| `skip` | `'**/index.html'` | Glob pattern for files to skip uploading. |
|
|
@@ -88,34 +134,21 @@ DEPLOY_OSS=1 pnpm build
|
|
|
88
134
|
- `configBase` affects both Vite's output asset paths and the URL addresses inside the manifest.
|
|
89
135
|
- `alias` only affects the URLs generated inside the manifest; it does not change the actual upload destination on OSS.
|
|
90
136
|
|
|
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
137
|
## Manifest
|
|
101
138
|
|
|
102
|
-
Enable manifest:
|
|
103
139
|
Enable manifest:
|
|
104
140
|
|
|
105
141
|
```ts
|
|
106
142
|
vitePluginDeployOss({
|
|
107
|
-
// ...other options
|
|
108
143
|
// ...other options
|
|
109
144
|
manifest: true,
|
|
110
145
|
})
|
|
111
146
|
```
|
|
112
147
|
|
|
113
|
-
Customize manifest filename:
|
|
114
148
|
Customize manifest filename:
|
|
115
149
|
|
|
116
150
|
```ts
|
|
117
151
|
vitePluginDeployOss({
|
|
118
|
-
// ...other options
|
|
119
152
|
// ...other options
|
|
120
153
|
manifest: {
|
|
121
154
|
fileName: 'meta/oss-manifest.json',
|
|
@@ -123,7 +156,6 @@ vitePluginDeployOss({
|
|
|
123
156
|
})
|
|
124
157
|
```
|
|
125
158
|
|
|
126
|
-
Manifest JSON example:
|
|
127
159
|
Manifest JSON example:
|
|
128
160
|
|
|
129
161
|
```json
|
|
@@ -142,27 +174,47 @@ Manifest JSON example:
|
|
|
142
174
|
|
|
143
175
|
## Debugging
|
|
144
176
|
|
|
145
|
-
## Debugging
|
|
146
|
-
|
|
147
|
-
Enable `debug` to log the time taken for each key step during deployment, which helps locate bottlenecks:
|
|
148
177
|
Enable `debug` to log the time taken for each key step during deployment, which helps locate bottlenecks:
|
|
149
178
|
|
|
150
179
|
```ts
|
|
151
180
|
vitePluginDeployOss({
|
|
152
|
-
// ...other options
|
|
153
181
|
// ...other options
|
|
154
182
|
debug: process.env.DEPLOY_OSS_DEBUG === '1',
|
|
155
183
|
})
|
|
156
184
|
```
|
|
157
185
|
|
|
158
|
-
You can also run the playground command in the project:
|
|
159
186
|
You can also run the playground command in the project:
|
|
160
187
|
|
|
161
188
|
```bash
|
|
162
189
|
pnpm run build:test:debug
|
|
163
190
|
```
|
|
164
191
|
|
|
165
|
-
##
|
|
192
|
+
## Local Upload Tests
|
|
193
|
+
|
|
194
|
+
The playground includes three upload test paths:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
# Vite plugin upload
|
|
198
|
+
pnpm run build:test:deploy
|
|
199
|
+
|
|
200
|
+
# Direct API upload
|
|
201
|
+
pnpm run deploy:test:api
|
|
202
|
+
|
|
203
|
+
# CLI upload
|
|
204
|
+
pnpm run deploy:test:cli
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
All three commands use the same environment variables as the playground:
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
zAccessKeyId=xxx
|
|
211
|
+
zAccessKeySecret=xxx
|
|
212
|
+
zBucket=xxx
|
|
213
|
+
zBucketAlias=https://example.com
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
The direct API test uploads `playground/__dist__` to `/test/__direct-api__/`.
|
|
217
|
+
The CLI test uploads `playground/__dist__` to `/test/__direct-cli__/`.
|
|
166
218
|
|
|
167
219
|
## Notes
|
|
168
220
|
|
|
@@ -170,7 +222,3 @@ pnpm run build:test:debug
|
|
|
170
222
|
- Keep `failOnError: true` for production builds to avoid completing the build/deployment pipeline when some files failed to upload.
|
|
171
223
|
- Make sure you do not need the local build directory before enabling `autoDelete`.
|
|
172
224
|
- 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.
|