-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.server.plugin.ts
More file actions
45 lines (43 loc) · 1.1 KB
/
vite.server.plugin.ts
File metadata and controls
45 lines (43 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
import { Plugin, ResolvedConfig } from "vite";
import path from "path";
import { NodeSSH } from "node-ssh";
export const serverPlugin = ({
host,
serverPath,
username,
password
}: {
host: string;
serverPath: string;
username: string;
password: string;
}): Plugin => {
let viteConfig: ResolvedConfig | null = null;
return {
name: "将本地打包文件推送到服务器上的指定路径",
configResolved(resolvedConfig: ResolvedConfig) {
viteConfig = resolvedConfig;
},
async closeBundle() {
const ssh = new NodeSSH();
console.log("路径", path.resolve(__dirname, "./key/id_rsa"));
await ssh.connect({
host,
username,
password
});
const buildPath = path.resolve(viteConfig?.build.outDir || "dist");
await ssh.execCommand(`rm -rf ${serverPath}/*`);
try {
await ssh.putDirectory(buildPath, serverPath, {
concurrency: 10,
recursive: true
});
} catch (error) {
console.log(error, "上传错误");
}
// 关闭服务器连接
ssh.dispose();
}
};
};