import fs from "fs"; import esbuild from "esbuild"; import sveltePlugin from "esbuild-svelte"; import sveltePreprocess from "svelte-preprocess"; import { glslify } from 'esbuild-plugin-glslify'; import fetch from "node-fetch"; const { PORT = 8080 } = process.env; const isDev = process.argv[2] === "--watch"; const sendReloadSignal = () => { fetch("http://localhost:" + PORT + "/reload", { method: "POST" }); } //make sure the directoy exists before stuff gets put into it if (!fs.existsSync("./public/build/")) { fs.mkdirSync("./public/build/") } //build the application esbuild.build({ entryPoints: ['./src/main.ts', './src/workers/ai-worker.ts', './src/workers/pixel-worker.ts'], outdir: './public/build', bundle: true, define: { IS_DEV: isDev, PORT }, minify: !isDev, sourcemap: true, watch: isDev ? { onRebuild(error, result) { if (error) console.error('watch build failed:', error) else { console.log('watch build succeeded'); sendReloadSignal() } } } : false, loader: { ".vert": "text", ".frag": "text" }, plugins: [sveltePlugin({ preprocess: sveltePreprocess() }), glslify({ extensions: ['vert', 'frag'], compress: true, })] }).catch((err) => { console.error(err) process.exit(1) })