|
| 1 | +const esbuild = require("esbuild"); |
| 2 | +const fs = require("fs-extra"); |
| 3 | +const path = require("path"); |
| 4 | +const production = process.argv.includes("--production"); |
| 5 | + |
| 6 | +async function main() { |
| 7 | + // Ensure output directory exists |
| 8 | + await fs.ensureDir("./dist/live2d-container"); |
| 9 | + |
| 10 | + // Bundle the Electron main process |
| 11 | + await esbuild.build({ |
| 12 | + entryPoints: ["live2d-container/main.js"], |
| 13 | + bundle: true, |
| 14 | + platform: "node", |
| 15 | + target: ["node16"], |
| 16 | + minify: production, |
| 17 | + sourcemap: !production, |
| 18 | + outfile: "dist/live2d-container/main.js", |
| 19 | + external: ["electron"], |
| 20 | + logLevel: "info" |
| 21 | + }); |
| 22 | + |
| 23 | + // Bundle the Electron preload script |
| 24 | + await esbuild.build({ |
| 25 | + entryPoints: ["live2d-container/preload.js"], |
| 26 | + bundle: true, |
| 27 | + platform: "node", |
| 28 | + target: ["node16"], |
| 29 | + minify: production, |
| 30 | + sourcemap: !production, |
| 31 | + outfile: "dist/live2d-container/preload.js", |
| 32 | + external: ["electron"], |
| 33 | + logLevel: "info" |
| 34 | + }); |
| 35 | + |
| 36 | + // Bundle the Electron renderer process (named index.js) |
| 37 | + await esbuild.build({ |
| 38 | + entryPoints: ["live2d-container/index.js"], |
| 39 | + bundle: true, |
| 40 | + platform: "browser", |
| 41 | + target: ["chrome90"], |
| 42 | + minify: production, |
| 43 | + sourcemap: !production, |
| 44 | + outfile: "dist/live2d-container/index.js", |
| 45 | + external: ["electron"], |
| 46 | + logLevel: "info" |
| 47 | + }); |
| 48 | + |
| 49 | + // Copy any HTML files |
| 50 | + const htmlFiles = await fs.readdir("live2d-container") |
| 51 | + .then(files => files.filter(file => file.endsWith(".html"))); |
| 52 | + |
| 53 | + for (const htmlFile of htmlFiles) { |
| 54 | + await fs.copy( |
| 55 | + path.join("live2d-container", htmlFile), |
| 56 | + path.join("dist/live2d-container", htmlFile) |
| 57 | + ); |
| 58 | + } |
| 59 | + |
| 60 | + // Copy all the .css files |
| 61 | + const cssFiles = await fs.readdir("live2d-container") |
| 62 | + .then(files => files.filter(file => file.endsWith(".css"))); |
| 63 | + for (const cssFile of cssFiles) { |
| 64 | + await fs.copy( |
| 65 | + path.join("live2d-container", cssFile), |
| 66 | + path.join("dist/live2d-container", cssFile) |
| 67 | + ); |
| 68 | + } |
| 69 | + |
| 70 | + await fs.copy("live2d-container/package.json", "dist/live2d-container/package.json"); |
| 71 | + |
| 72 | + console.log("Overlay build complete!"); |
| 73 | +} |
| 74 | + |
| 75 | +main().catch(error => { |
| 76 | + console.error("Build failed:", error); |
| 77 | + process.exit(1); |
| 78 | +}); |
0 commit comments