aether-shards/build.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

2025-12-17 19:26:42 +00:00
import { build } from "esbuild";
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);
// 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({
entryPoints: ["src/index.js"],
2025-12-16 23:52:58 +00:00
bundle: true,
splitting: true,
2025-12-17 19:26:42 +00:00
format: "esm",
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
// Copy images
copyImages("src", "dist");
2025-12-17 19:26:42 +00:00
console.log("Build complete!");