-
Notifications
You must be signed in to change notification settings - Fork 583
Expand file tree
/
Copy pathdeploy.mjs
More file actions
30 lines (26 loc) · 1.12 KB
/
Copy pathdeploy.mjs
File metadata and controls
30 lines (26 loc) · 1.12 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
/**
* 部署管理后台到服务器 | 用法:pnpm run deploy
*
* 前置:SSH 免密登录(只需一次)
* 1. 如果 %USERPROFILE%\.ssh\id_rsa 已存在跳过,否则 ssh-keygen -t rsa 回车到底
*
* 2. 拷贝公钥到服务器(会提示输一次服务器密码):
* Windows: type %USERPROFILE%\.ssh\id_rsa.pub | ssh root@server "cat >> ~/.ssh/authorized_keys"
* Mac: ssh-copy-id root@server
*
* 3. ssh root@server 输完不弹密码直接连上即成功
*/
import { execSync } from "node:child_process";
const HOST = "127.0.0.1"; // 服务器 IP,改为你的
const USER = "root"; // SSH 用户名,改为你的
const PORT = 22; // SSH 端口,改为你的
const TARGET = "/data/www/vue3-element-admin"; // 部署目录,改为你的
// =========================================================
console.log("构建中...");
execSync("pnpm build-only", { stdio: "inherit" });
console.log(`部署 → ${USER}@${HOST}:${TARGET}`);
execSync(`scp -o StrictHostKeyChecking=no -P ${PORT} -r "dist/." "${USER}@${HOST}:${TARGET}/"`, {
stdio: "inherit",
shell: true,
});
console.log("部署完成");