@yidun/cdn-upload-webpack-plugin 1.1.4 → 1.1.6
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/package.json +1 -1
- package/src/index.js +15 -3
- package/src/vite.js +5 -1
- package/example/.vscode/extensions.json +0 -3
- package/example/README.md +0 -4
- package/example/index.html +0 -13
- package/example/package-lock.json +0 -1162
- package/example/package.json +0 -21
- package/example/public/vite.svg +0 -1
- package/example/src/App.vue +0 -30
- package/example/src/assets/vue.svg +0 -1
- package/example/src/components/HelloWorld.vue +0 -39
- package/example/src/main.ts +0 -5
- package/example/src/style.css +0 -79
- package/example/src/vite-env.d.ts +0 -1
- package/example/tsconfig.json +0 -25
- package/example/tsconfig.node.json +0 -11
- package/example/vite.config.ts +0 -25
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const fetch = require('node-fetch')
|
|
1
2
|
const { getFiles } = require('./utils')
|
|
2
3
|
const { TaskDispatcher } = require('./task')
|
|
3
4
|
const NosUploadTask = require('./adaptor/nos')
|
|
@@ -17,12 +18,13 @@ exports.CdnUploadWebpackPlugin = class CdnUploadWebpackPlugin {
|
|
|
17
18
|
* @param {Number} parallelCount 并行上传数, 默认 3
|
|
18
19
|
*/
|
|
19
20
|
constructor (options) {
|
|
20
|
-
const { dirs, includeRootDir, ignores, client, parallelCount } = options
|
|
21
|
+
const { dirs, includeRootDir, ignores, client, parallelCount, domain = 'https://yidunfe.nosdn.127.net' } = options
|
|
21
22
|
this._dirs = dirs
|
|
22
23
|
this._includeRootDir = includeRootDir
|
|
23
24
|
this._ignores = ignores
|
|
24
25
|
this._client = client
|
|
25
26
|
this._parallelCount = parallelCount
|
|
27
|
+
this._domain = domain
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
apply (compiler) {
|
|
@@ -30,8 +32,18 @@ exports.CdnUploadWebpackPlugin = class CdnUploadWebpackPlugin {
|
|
|
30
32
|
const files = getFiles(this._dirs, this._includeRootDir, this._ignores)
|
|
31
33
|
const tasks = files.map(file => new NosUploadTask(this._client, file))
|
|
32
34
|
const taskDispatcher = new TaskDispatcher(tasks, {
|
|
33
|
-
onSuccess: () => {
|
|
34
|
-
|
|
35
|
+
onSuccess: async (task) => {
|
|
36
|
+
if (!task) {
|
|
37
|
+
callback(new Error('CdnUploadVitePlugin Error: task is empty'))
|
|
38
|
+
return
|
|
39
|
+
}
|
|
40
|
+
// cdn 上传成功后健康检查
|
|
41
|
+
const { _file, _namespace } = task[0] || {}
|
|
42
|
+
const data = await fetch(`${this._domain}/${_namespace}/${_file.relative}`)
|
|
43
|
+
if (!data.ok || data.status !== 200) {
|
|
44
|
+
callback(new Error(`CdnUploadVitePlugin Error: url: ${data.url}, status: ${data.status}`))
|
|
45
|
+
}
|
|
46
|
+
console.log('CdnUploadVitePlugin: assets upload success')
|
|
35
47
|
callback()
|
|
36
48
|
},
|
|
37
49
|
onError: error => callback(error)
|
package/src/vite.js
CHANGED
|
@@ -26,8 +26,12 @@ function CdnUploadVitePlugin (options) {
|
|
|
26
26
|
return new Promise((resolve, reject) => {
|
|
27
27
|
const taskDispatcher = new TaskDispatcher(tasks, {
|
|
28
28
|
onSuccess: async (task) => {
|
|
29
|
+
if (!task) {
|
|
30
|
+
reject(new Error('CdnUploadVitePlugin Error: task is empty'))
|
|
31
|
+
return
|
|
32
|
+
}
|
|
29
33
|
// cdn 上传成功后健康检查
|
|
30
|
-
const { _file, _namespace } = task
|
|
34
|
+
const { _file, _namespace } = task[0] || {}
|
|
31
35
|
const data = await fetch(`${domain}/${_namespace}/${_file.relative}`)
|
|
32
36
|
if (!data.ok || data.status !== 200) {
|
|
33
37
|
reject(new Error(`CdnUploadVitePlugin Error: url: ${data.url}, status: ${data.status}`))
|
package/example/README.md
DELETED
package/example/index.html
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
-
<title>Vite + Vue + TS</title>
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<div id="app"></div>
|
|
11
|
-
<script type="module" src="/src/main.ts"></script>
|
|
12
|
-
</body>
|
|
13
|
-
</html>
|