2023-11-01 22:29:43 +08:00
|
|
|
import { execaCommand } from "execa";
|
|
|
|
import path from "path";
|
|
|
|
import fsExtra from "fs-extra";
|
|
|
|
const { existsSync, remove, copy } = fsExtra;
|
|
|
|
const cwd = process.cwd();
|
2023-10-29 18:37:44 +08:00
|
|
|
//打包发布路径,谨慎改动
|
2023-11-01 22:29:43 +08:00
|
|
|
const releaseRelativePath = "../public/admin";
|
|
|
|
const distPath = path.resolve(cwd, "dist");
|
|
|
|
const releasePath = path.resolve(cwd, releaseRelativePath);
|
2023-10-29 18:37:44 +08:00
|
|
|
|
|
|
|
async function build() {
|
2023-11-01 22:29:43 +08:00
|
|
|
await execaCommand("vite build", {
|
|
|
|
stdio: "inherit",
|
|
|
|
encoding: "utf-8",
|
|
|
|
cwd,
|
|
|
|
});
|
|
|
|
if (existsSync(releasePath)) {
|
|
|
|
await remove(releasePath);
|
|
|
|
}
|
|
|
|
console.log(`文件正在复制 ==> ${releaseRelativePath}`);
|
|
|
|
try {
|
|
|
|
await copyFile(distPath, releasePath);
|
|
|
|
} catch (error) {
|
|
|
|
console.log(`\n ${error}`);
|
|
|
|
}
|
|
|
|
console.log(`文件已复制 ==> ${releaseRelativePath}`);
|
2023-10-29 18:37:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function copyFile(sourceDir, targetDir) {
|
2023-11-01 22:29:43 +08:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
copy(sourceDir, targetDir, (err) => {
|
|
|
|
if (err) {
|
|
|
|
reject(err);
|
|
|
|
} else {
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2023-10-29 18:37:44 +08:00
|
|
|
}
|
|
|
|
|
2023-11-01 22:29:43 +08:00
|
|
|
build();
|