91 lines
2.4 KiB
JavaScript
91 lines
2.4 KiB
JavaScript
import esbuild from "esbuild";
|
|
import fs from "fs";
|
|
import path from "path";
|
|
|
|
const watch = process.argv.includes("--watch");
|
|
|
|
const copyAssets = {
|
|
name: "copy-assets",
|
|
setup(build) {
|
|
build.onEnd(() => {
|
|
fs.mkdirSync("dist", { recursive: true });
|
|
fs.copyFileSync(
|
|
path.join("src", "renderer", "index.html"),
|
|
path.join("dist", "index.html")
|
|
);
|
|
fs.copyFileSync(
|
|
path.join("src", "renderer", "index.css"),
|
|
path.join("dist", "index.css")
|
|
);
|
|
fs.copyFileSync(
|
|
path.join("src", "renderer", "themes.css"),
|
|
path.join("dist", "themes.css")
|
|
);
|
|
fs.copyFileSync(
|
|
path.join("src", "renderer", "fonts.css"),
|
|
path.join("dist", "fonts.css")
|
|
);
|
|
fs.mkdirSync(path.join("dist", "icons"), { recursive: true });
|
|
fs.copyFileSync(
|
|
path.join("build", "icons", "256x256.png"),
|
|
path.join("dist", "icons", "icon.png")
|
|
);
|
|
fs.copyFileSync(
|
|
path.join("build", "icons", "128x128.png"),
|
|
path.join("dist", "brand-icon.png")
|
|
);
|
|
fs.copyFileSync(
|
|
path.join("build", "brand-icons", "128x128-black.png"),
|
|
path.join("dist", "brand-icon-black.png")
|
|
);
|
|
// Bundle locally-stored fonts so the app needs no network at runtime.
|
|
fs.mkdirSync(path.join("dist", "fonts"), { recursive: true });
|
|
const fontsDir = path.join("public", "fonts");
|
|
if (fs.existsSync(fontsDir)) {
|
|
for (const f of fs.readdirSync(fontsDir)) {
|
|
fs.copyFileSync(path.join(fontsDir, f), path.join("dist", "fonts", f));
|
|
}
|
|
}
|
|
});
|
|
},
|
|
};
|
|
|
|
const common = {
|
|
bundle: true,
|
|
sourcemap: true,
|
|
logLevel: "info",
|
|
};
|
|
|
|
const main = {
|
|
entryPoints: ["src/main/index.ts"],
|
|
platform: "node",
|
|
external: ["electron"],
|
|
outfile: "dist/main.js",
|
|
plugins: [copyAssets],
|
|
...common,
|
|
};
|
|
|
|
const preload = {
|
|
entryPoints: ["src/main/preload.ts"],
|
|
platform: "node",
|
|
external: ["electron"],
|
|
outfile: "dist/preload.js",
|
|
plugins: [copyAssets],
|
|
...common,
|
|
};
|
|
|
|
const renderer = {
|
|
entryPoints: ["src/renderer/index.ts"],
|
|
platform: "browser",
|
|
outfile: "dist/renderer.js",
|
|
...common,
|
|
};
|
|
|
|
const builds = [main, preload, renderer];
|
|
|
|
if (watch) {
|
|
const contexts = await Promise.all(builds.map((opts) => esbuild.context(opts)));
|
|
await Promise.all(contexts.map((ctx) => ctx.watch()));
|
|
} else {
|
|
await Promise.all(builds.map((opts) => esbuild.build(opts)));
|
|
}
|