forked from kleneway/pastemax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
executable file
·45 lines (38 loc) · 1.4 KB
/
build.js
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
/* eslint-disable @typescript-eslint/no-var-requires */
const { execSync } = require("child_process");
const fs = require("fs");
const path = require("path");
async function main() {
try {
console.log("📦 Building React app with Vite...");
execSync("npm run build", { stdio: "inherit" });
console.log("✅ React build completed successfully!");
// Fix the paths in index.html for Electron compatibility
const indexHtmlPath = path.join(__dirname, "dist", "index.html");
if (fs.existsSync(indexHtmlPath)) {
let content = fs.readFileSync(indexHtmlPath, "utf8");
// Fix asset paths for Electron's file:// protocol
content = content.replace(/\/assets\//g, "./assets/");
content = content.replace(/(src|href)=["']\//g, '$1="./');
content = content.replace(
/(src|href)=["']\.\.\/assets\//g,
'$1="./assets/',
);
fs.writeFileSync(indexHtmlPath, content);
console.log(
"🔄 Updated asset paths in index.html for Electron compatibility",
);
}
console.log(
"🚀 Build process completed! The app is ready to run with Electron.",
);
// Package the app
console.log("📦 Packaging application...");
execSync("npm run package", { stdio: "inherit" });
console.log("✅ Packaging completed!");
} catch (error) {
console.error("❌ Build failed:", error.message);
process.exit(1);
}
}
main();