2025-12-17 19:26:42 +00:00
|
|
|
import { build } from "esbuild";
|
2025-12-19 23:07:36 +00:00
|
|
|
import { copyFileSync, mkdirSync, readdirSync } from "fs";
|
|
|
|
|
import { dirname, join } from "path";
|
2025-12-17 19:26:42 +00:00
|
|
|
import { fileURLToPath } from "url";
|
2025-12-16 23:52:58 +00:00
|
|
|
|
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
|
|
|
const __dirname = dirname(__filename);
|
|
|
|
|
|
2025-12-19 23:07:36 +00:00
|
|
|
// Image file extensions to copy
|
|
|
|
|
const IMAGE_EXTENSIONS = [".png", ".jpg", ".jpeg", ".gif", ".svg", ".webp"];
|
|
|
|
|
|
|
|
|
|
// Recursively copy image files from src to dist
|
|
|
|
|
function copyImages(srcDir, distDir) {
|
|
|
|
|
const entries = readdirSync(srcDir, { withFileTypes: true });
|
|
|
|
|
|
|
|
|
|
for (const entry of entries) {
|
|
|
|
|
const srcPath = join(srcDir, entry.name);
|
|
|
|
|
const distPath = join(distDir, entry.name);
|
|
|
|
|
|
|
|
|
|
if (entry.isDirectory()) {
|
|
|
|
|
mkdirSync(distPath, { recursive: true });
|
|
|
|
|
copyImages(srcPath, distPath);
|
|
|
|
|
} else if (entry.isFile()) {
|
|
|
|
|
const lastDot = entry.name.lastIndexOf(".");
|
|
|
|
|
if (lastDot !== -1) {
|
|
|
|
|
const ext = entry.name.toLowerCase().substring(lastDot);
|
|
|
|
|
if (IMAGE_EXTENSIONS.includes(ext)) {
|
|
|
|
|
mkdirSync(distDir, { recursive: true });
|
|
|
|
|
copyFileSync(srcPath, distPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-16 23:52:58 +00:00
|
|
|
// Ensure dist directory exists
|
2025-12-17 19:26:42 +00:00
|
|
|
mkdirSync("dist", { recursive: true });
|
2025-12-16 23:52:58 +00:00
|
|
|
|
|
|
|
|
// Build JavaScript
|
|
|
|
|
await build({
|
2025-12-19 16:38:22 +00:00
|
|
|
entryPoints: ["src/index.js"],
|
2025-12-16 23:52:58 +00:00
|
|
|
bundle: true,
|
2025-12-19 16:38:22 +00:00
|
|
|
splitting: true,
|
2025-12-17 19:26:42 +00:00
|
|
|
format: "esm",
|
2025-12-19 16:38:22 +00:00
|
|
|
outdir: "dist",
|
2025-12-17 19:26:42 +00:00
|
|
|
sourcemap: true,
|
|
|
|
|
platform: "browser",
|
2025-12-16 23:52:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Copy HTML file
|
2025-12-17 19:26:42 +00:00
|
|
|
copyFileSync("src/index.html", "dist/index.html");
|
2025-12-16 23:52:58 +00:00
|
|
|
|
2025-12-19 23:07:36 +00:00
|
|
|
// Copy images
|
|
|
|
|
copyImages("src", "dist");
|
|
|
|
|
|
2025-12-17 19:26:42 +00:00
|
|
|
console.log("Build complete!");
|