@yidun/cdn-upload-webpack-plugin 1.1.1 → 1.1.3
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/.eslintignore +2 -2
- package/.eslintrc.js +9 -9
- package/README.md +44 -44
- package/example/.vscode/extensions.json +3 -0
- package/example/README.md +4 -0
- package/example/index.html +13 -0
- package/example/package-lock.json +1162 -0
- package/example/package.json +21 -0
- package/example/public/vite.svg +1 -0
- package/example/src/App.vue +30 -0
- package/example/src/assets/vue.svg +1 -0
- package/example/src/components/HelloWorld.vue +38 -0
- package/example/src/main.ts +5 -0
- package/example/src/style.css +79 -0
- package/example/src/vite-env.d.ts +1 -0
- package/example/tsconfig.json +25 -0
- package/example/tsconfig.node.json +11 -0
- package/example/vite.config.ts +25 -0
- package/package.json +24 -23
- package/src/adaptor/nos.js +39 -45
- package/src/index.js +45 -45
- package/src/task.js +103 -103
- package/src/utils.js +41 -41
- package/src/vite.js +46 -39
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "example",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "vue-tsc && vite build",
|
|
9
|
+
"preview": "vite preview"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"vue": "^3.4.21"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@types/node": "^20.12.3",
|
|
16
|
+
"@vitejs/plugin-vue": "^5.0.4",
|
|
17
|
+
"typescript": "^5.2.2",
|
|
18
|
+
"vite": "^5.2.0",
|
|
19
|
+
"vue-tsc": "^2.0.6"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import HelloWorld from './components/HelloWorld.vue'
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<template>
|
|
6
|
+
<div>
|
|
7
|
+
<a href="https://vitejs.dev" target="_blank">
|
|
8
|
+
<img src="/vite.svg" class="logo" alt="Vite logo" />
|
|
9
|
+
</a>
|
|
10
|
+
<a href="https://vuejs.org/" target="_blank">
|
|
11
|
+
<img src="./assets/vue.svg" class="logo vue" alt="Vue logo" />
|
|
12
|
+
</a>
|
|
13
|
+
</div>
|
|
14
|
+
<HelloWorld msg="Vite + Vue3" />
|
|
15
|
+
</template>
|
|
16
|
+
|
|
17
|
+
<style scoped>
|
|
18
|
+
.logo {
|
|
19
|
+
height: 6em;
|
|
20
|
+
padding: 1.5em;
|
|
21
|
+
will-change: filter;
|
|
22
|
+
transition: filter 300ms;
|
|
23
|
+
}
|
|
24
|
+
.logo:hover {
|
|
25
|
+
filter: drop-shadow(0 0 2em #646cffaa);
|
|
26
|
+
}
|
|
27
|
+
.logo.vue:hover {
|
|
28
|
+
filter: drop-shadow(0 0 2em #42b883aa);
|
|
29
|
+
}
|
|
30
|
+
</style>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref } from 'vue'
|
|
3
|
+
|
|
4
|
+
defineProps<{ msg: string }>()
|
|
5
|
+
|
|
6
|
+
const count = ref(0)
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<template>
|
|
10
|
+
<h1>{{ msg }}</h1>
|
|
11
|
+
|
|
12
|
+
<div class="card">
|
|
13
|
+
<button type="button" @click="count++">count is {{ count }}</button>
|
|
14
|
+
<p>
|
|
15
|
+
Edit
|
|
16
|
+
<code>components/HelloWorld.vue</code> to test HMR
|
|
17
|
+
</p>
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
<p>
|
|
21
|
+
Check out
|
|
22
|
+
<a href="https://vuejs.org/guide/quick-start.html#local" target="_blank"
|
|
23
|
+
>create-vue</a
|
|
24
|
+
>, the official Vue + Vite starter
|
|
25
|
+
</p>
|
|
26
|
+
<p>
|
|
27
|
+
Install
|
|
28
|
+
<a href="https://github.com/vuejs/language-tools" target="_blank">Volar</a>
|
|
29
|
+
in your IDE for a better DX
|
|
30
|
+
</p>
|
|
31
|
+
<p class="read-the-docs">Click on the Vite and Vue logos to learn more</p>
|
|
32
|
+
</template>
|
|
33
|
+
|
|
34
|
+
<style scoped>
|
|
35
|
+
.read-the-docs {
|
|
36
|
+
color: #888;
|
|
37
|
+
}
|
|
38
|
+
</style>
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
|
3
|
+
line-height: 1.5;
|
|
4
|
+
font-weight: 400;
|
|
5
|
+
|
|
6
|
+
color-scheme: light dark;
|
|
7
|
+
color: rgba(255, 255, 255, 0.87);
|
|
8
|
+
background-color: #242424;
|
|
9
|
+
|
|
10
|
+
font-synthesis: none;
|
|
11
|
+
text-rendering: optimizeLegibility;
|
|
12
|
+
-webkit-font-smoothing: antialiased;
|
|
13
|
+
-moz-osx-font-smoothing: grayscale;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
a {
|
|
17
|
+
font-weight: 500;
|
|
18
|
+
color: #646cff;
|
|
19
|
+
text-decoration: inherit;
|
|
20
|
+
}
|
|
21
|
+
a:hover {
|
|
22
|
+
color: #535bf2;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
body {
|
|
26
|
+
margin: 0;
|
|
27
|
+
display: flex;
|
|
28
|
+
place-items: center;
|
|
29
|
+
min-width: 320px;
|
|
30
|
+
min-height: 100vh;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
h1 {
|
|
34
|
+
font-size: 3.2em;
|
|
35
|
+
line-height: 1.1;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
button {
|
|
39
|
+
border-radius: 8px;
|
|
40
|
+
border: 1px solid transparent;
|
|
41
|
+
padding: 0.6em 1.2em;
|
|
42
|
+
font-size: 1em;
|
|
43
|
+
font-weight: 500;
|
|
44
|
+
font-family: inherit;
|
|
45
|
+
background-color: #1a1a1a;
|
|
46
|
+
cursor: pointer;
|
|
47
|
+
transition: border-color 0.25s;
|
|
48
|
+
}
|
|
49
|
+
button:hover {
|
|
50
|
+
border-color: #646cff;
|
|
51
|
+
}
|
|
52
|
+
button:focus,
|
|
53
|
+
button:focus-visible {
|
|
54
|
+
outline: 4px auto -webkit-focus-ring-color;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.card {
|
|
58
|
+
padding: 2em;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
#app {
|
|
62
|
+
max-width: 1280px;
|
|
63
|
+
margin: 0 auto;
|
|
64
|
+
padding: 2rem;
|
|
65
|
+
text-align: center;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@media (prefers-color-scheme: light) {
|
|
69
|
+
:root {
|
|
70
|
+
color: #213547;
|
|
71
|
+
background-color: #ffffff;
|
|
72
|
+
}
|
|
73
|
+
a:hover {
|
|
74
|
+
color: #747bff;
|
|
75
|
+
}
|
|
76
|
+
button {
|
|
77
|
+
background-color: #f9f9f9;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
|
|
9
|
+
/* Bundler mode */
|
|
10
|
+
"moduleResolution": "bundler",
|
|
11
|
+
"allowImportingTsExtensions": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
"jsx": "preserve",
|
|
16
|
+
|
|
17
|
+
/* Linting */
|
|
18
|
+
"strict": true,
|
|
19
|
+
"noUnusedLocals": true,
|
|
20
|
+
"noUnusedParameters": true,
|
|
21
|
+
"noFallthroughCasesInSwitch": true
|
|
22
|
+
},
|
|
23
|
+
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
|
|
24
|
+
"references": [{ "path": "./tsconfig.node.json" }]
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { defineConfig } from 'vite'
|
|
2
|
+
import vue from '@vitejs/plugin-vue'
|
|
3
|
+
import { CdnUploadVitePlugin } from '@yidun/cdn-upload-webpack-plugin'
|
|
4
|
+
import path from 'path'
|
|
5
|
+
|
|
6
|
+
// https://vitejs.dev/config/
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
base: 'https://yidunfe.nosdn.127.net/test-upload/',
|
|
9
|
+
plugins: [
|
|
10
|
+
vue(),
|
|
11
|
+
CdnUploadVitePlugin({
|
|
12
|
+
dirs: path.join(__dirname, 'dist'),
|
|
13
|
+
includeRootDir: false,
|
|
14
|
+
ignore: [/\.html$/, /\.map$/],
|
|
15
|
+
parallelCount: Infinity,
|
|
16
|
+
client: {
|
|
17
|
+
bucket: 'yidunfe',
|
|
18
|
+
accessId: 'e36babfdcb884368b4e72670e1a08d6a',
|
|
19
|
+
secretKey: '9d14ac7ba4054498858b572cd9e28c54',
|
|
20
|
+
endpoint: 'nos-jd.163yun.com',
|
|
21
|
+
namespace: 'test-upload'
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
],
|
|
25
|
+
})
|
package/package.json
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@yidun/cdn-upload-webpack-plugin",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "A webpack plugin for upload dist to cdn.",
|
|
5
|
-
"main": "src/index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "node test/index.js"
|
|
8
|
-
},
|
|
9
|
-
"author": "zhanglulu01",
|
|
10
|
-
"license": "ISC",
|
|
11
|
-
"devDependencies": {
|
|
12
|
-
"eslint": "^7.14.0",
|
|
13
|
-
"eslint-config-standard": "^16.0.2",
|
|
14
|
-
"eslint-plugin-import": "^2.22.1",
|
|
15
|
-
"eslint-plugin-node": "^11.1.0",
|
|
16
|
-
"eslint-plugin-promise": "^4.2.1",
|
|
17
|
-
"eslint-plugin-standard": "^5.0.0"
|
|
18
|
-
},
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@yidun/cdn-upload-webpack-plugin",
|
|
3
|
+
"version": "1.1.3",
|
|
4
|
+
"description": "A webpack plugin for upload dist to cdn.",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "node test/index.js"
|
|
8
|
+
},
|
|
9
|
+
"author": "zhanglulu01",
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"eslint": "^7.14.0",
|
|
13
|
+
"eslint-config-standard": "^16.0.2",
|
|
14
|
+
"eslint-plugin-import": "^2.22.1",
|
|
15
|
+
"eslint-plugin-node": "^11.1.0",
|
|
16
|
+
"eslint-plugin-promise": "^4.2.1",
|
|
17
|
+
"eslint-plugin-standard": "^5.0.0"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@xgheaven/nos-node-sdk": "^0.2.5",
|
|
21
|
+
"bluebird": "^3.7.2",
|
|
22
|
+
"node-fetch": "^2.7.0"
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/adaptor/nos.js
CHANGED
|
@@ -1,45 +1,39 @@
|
|
|
1
|
-
const { Task } = require('../task')
|
|
2
|
-
const NosClient = require('nos-node-
|
|
3
|
-
const { normalizeObjectKey } = require('../utils')
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const { accessId, secretKey, bucket, endpoint = 'nos.netease.com',
|
|
10
|
-
nosClient
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
module.exports = NosUploadTask
|
|
1
|
+
const { Task } = require('../task')
|
|
2
|
+
const { NosClient } = require('@xgheaven/nos-node-sdk')
|
|
3
|
+
const { normalizeObjectKey } = require('../utils')
|
|
4
|
+
const fs = require('fs')
|
|
5
|
+
|
|
6
|
+
class NosUploadTask extends Task {
|
|
7
|
+
constructor (nosOptions, file) {
|
|
8
|
+
super(() => this.upload())
|
|
9
|
+
const { accessId, secretKey, bucket, endpoint = 'nos.netease.com', namespace = '' } = nosOptions
|
|
10
|
+
const nosClient = new NosClient({
|
|
11
|
+
accessKey: accessId,
|
|
12
|
+
accessSecret: secretKey,
|
|
13
|
+
endpoint: `https://${endpoint}`,
|
|
14
|
+
defaultBucket: bucket
|
|
15
|
+
})
|
|
16
|
+
this._nosClient = nosClient
|
|
17
|
+
this._bucket = bucket
|
|
18
|
+
this._file = file
|
|
19
|
+
this._namespace = namespace
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
upload () {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
try {
|
|
25
|
+
const stream = fs.createReadStream(this._file.path)
|
|
26
|
+
const data = this._nosClient.putObject({
|
|
27
|
+
body: stream,
|
|
28
|
+
objectKey: normalizeObjectKey(`${this._namespace}/${this._file.relative}`)
|
|
29
|
+
})
|
|
30
|
+
resolve(data)
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error(`upload to nos fail, because ${error}`)
|
|
33
|
+
reject(error)
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = NosUploadTask
|
package/src/index.js
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
const { getFiles } = require('./utils')
|
|
2
|
-
const { TaskDispatcher } = require('./task')
|
|
3
|
-
const NosUploadTask = require('./adaptor/nos')
|
|
4
|
-
const CdnUploadVitePlugin = require('./vite')
|
|
5
|
-
|
|
6
|
-
exports.CdnUploadWebpackPlugin = class CdnUploadWebpackPlugin {
|
|
7
|
-
/**
|
|
8
|
-
* @param {Object} options
|
|
9
|
-
* @param {Array|String} dirs 待上传的文件目录
|
|
10
|
-
* @param {Boolean} includeRootDir 文件的相对路径计算时包不包含根目录,默认 true
|
|
11
|
-
* @param {RegExp|Array<RegExp>} ignores 排除特定文件
|
|
12
|
-
* @param {Object} client 上传 client 配置,目前只支持 NosClient,不同的 client 配置参数可能不同,以 nos 举例
|
|
13
|
-
* @param {String} accessId
|
|
14
|
-
* @param {String} secretKey
|
|
15
|
-
* @param {String} bucket 桶名
|
|
16
|
-
* @param {String} namespace 不同项目在使用同一个桶时做隔离
|
|
17
|
-
* @param {Number} parallelCount 并行上传数, 默认 3
|
|
18
|
-
*/
|
|
19
|
-
constructor (options) {
|
|
20
|
-
const { dirs, includeRootDir, ignores, client, parallelCount } = options
|
|
21
|
-
this._dirs = dirs
|
|
22
|
-
this._includeRootDir = includeRootDir
|
|
23
|
-
this._ignores = ignores
|
|
24
|
-
this._client = client
|
|
25
|
-
this._parallelCount = parallelCount
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
apply (compiler) {
|
|
29
|
-
compiler.hooks.afterEmit.tapAsync('CdnUploadWebpackPlugin', (compiler, callback) => {
|
|
30
|
-
const files = getFiles(this._dirs, this._includeRootDir, this._ignores)
|
|
31
|
-
const tasks = files.map(file => new NosUploadTask(this._client, file))
|
|
32
|
-
const taskDispatcher = new TaskDispatcher(tasks, {
|
|
33
|
-
onSuccess: () => {
|
|
34
|
-
console.log('CdnUploadWebpackPlugin: assets upload success')
|
|
35
|
-
callback()
|
|
36
|
-
},
|
|
37
|
-
onError: error => callback(error)
|
|
38
|
-
})
|
|
39
|
-
console.log('CdnUploadWebpackPlugin: assets uploading ...')
|
|
40
|
-
taskDispatcher.dispatch(this._parallelCount)
|
|
41
|
-
})
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
exports.CdnUploadVitePlugin = CdnUploadVitePlugin
|
|
1
|
+
const { getFiles } = require('./utils')
|
|
2
|
+
const { TaskDispatcher } = require('./task')
|
|
3
|
+
const NosUploadTask = require('./adaptor/nos')
|
|
4
|
+
const CdnUploadVitePlugin = require('./vite')
|
|
5
|
+
|
|
6
|
+
exports.CdnUploadWebpackPlugin = class CdnUploadWebpackPlugin {
|
|
7
|
+
/**
|
|
8
|
+
* @param {Object} options
|
|
9
|
+
* @param {Array|String} dirs 待上传的文件目录
|
|
10
|
+
* @param {Boolean} includeRootDir 文件的相对路径计算时包不包含根目录,默认 true
|
|
11
|
+
* @param {RegExp|Array<RegExp>} ignores 排除特定文件
|
|
12
|
+
* @param {Object} client 上传 client 配置,目前只支持 NosClient,不同的 client 配置参数可能不同,以 nos 举例
|
|
13
|
+
* @param {String} accessId
|
|
14
|
+
* @param {String} secretKey
|
|
15
|
+
* @param {String} bucket 桶名
|
|
16
|
+
* @param {String} namespace 不同项目在使用同一个桶时做隔离
|
|
17
|
+
* @param {Number} parallelCount 并行上传数, 默认 3
|
|
18
|
+
*/
|
|
19
|
+
constructor (options) {
|
|
20
|
+
const { dirs, includeRootDir, ignores, client, parallelCount } = options
|
|
21
|
+
this._dirs = dirs
|
|
22
|
+
this._includeRootDir = includeRootDir
|
|
23
|
+
this._ignores = ignores
|
|
24
|
+
this._client = client
|
|
25
|
+
this._parallelCount = parallelCount
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
apply (compiler) {
|
|
29
|
+
compiler.hooks.afterEmit.tapAsync('CdnUploadWebpackPlugin', (compiler, callback) => {
|
|
30
|
+
const files = getFiles(this._dirs, this._includeRootDir, this._ignores)
|
|
31
|
+
const tasks = files.map(file => new NosUploadTask(this._client, file))
|
|
32
|
+
const taskDispatcher = new TaskDispatcher(tasks, {
|
|
33
|
+
onSuccess: () => {
|
|
34
|
+
console.log('CdnUploadWebpackPlugin: assets upload success')
|
|
35
|
+
callback()
|
|
36
|
+
},
|
|
37
|
+
onError: error => callback(error)
|
|
38
|
+
})
|
|
39
|
+
console.log('CdnUploadWebpackPlugin: assets uploading ...')
|
|
40
|
+
taskDispatcher.dispatch(this._parallelCount)
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
exports.CdnUploadVitePlugin = CdnUploadVitePlugin
|