2023-03-29 23:02:30 +00:00
|
|
|
import { BuildContext, BuildOptions, context } from "esbuild";
|
|
|
|
|
2023-04-04 02:40:03 +00:00
|
|
|
const CommonOpts: BuildOptions = {
|
2023-03-29 23:02:30 +00:00
|
|
|
minify: true,
|
|
|
|
bundle: true,
|
|
|
|
sourcemap: "linked",
|
|
|
|
logLevel: "info"
|
|
|
|
};
|
|
|
|
|
2023-04-04 02:40:03 +00:00
|
|
|
const NodeCommonOpts: BuildOptions = {
|
|
|
|
...CommonOpts,
|
|
|
|
format: "cjs",
|
|
|
|
platform: "node",
|
|
|
|
external: ["electron"],
|
|
|
|
target: ["esnext"],
|
|
|
|
};
|
|
|
|
|
2023-03-29 23:02:30 +00:00
|
|
|
const contexts = [] as BuildContext[];
|
|
|
|
async function createContext(options: BuildOptions) {
|
|
|
|
contexts.push(await context(options));
|
|
|
|
}
|
|
|
|
|
|
|
|
await Promise.all([
|
|
|
|
createContext({
|
|
|
|
...NodeCommonOpts,
|
|
|
|
entryPoints: ["src/main/index.ts"],
|
2023-04-03 03:44:17 +00:00
|
|
|
outfile: "dist/js/main.js"
|
2023-03-29 23:02:30 +00:00
|
|
|
}),
|
|
|
|
createContext({
|
|
|
|
...NodeCommonOpts,
|
|
|
|
entryPoints: ["src/preload/index.ts"],
|
2023-04-03 03:44:17 +00:00
|
|
|
outfile: "dist/js/preload.js"
|
2023-04-04 02:40:03 +00:00
|
|
|
}),
|
|
|
|
createContext({
|
|
|
|
...CommonOpts,
|
2023-04-08 23:20:00 +00:00
|
|
|
globalName: "VencordDesktop",
|
2023-04-04 02:40:03 +00:00
|
|
|
entryPoints: ["src/renderer/index.ts"],
|
|
|
|
outfile: "dist/js/renderer.js",
|
|
|
|
format: "iife",
|
2023-04-08 22:49:47 +00:00
|
|
|
inject: ["./scripts/build/injectReact.mjs"],
|
|
|
|
jsxFactory: "VencordCreateElement",
|
|
|
|
jsxFragment: "VencordFragment",
|
|
|
|
// Work around https://github.com/evanw/esbuild/issues/2460
|
|
|
|
tsconfig: "./scripts/build/tsconfig.esbuild.json"
|
2023-03-29 23:02:30 +00:00
|
|
|
})
|
|
|
|
]);
|
|
|
|
|
|
|
|
const watch = process.argv.includes("--watch");
|
|
|
|
|
|
|
|
if (watch) {
|
|
|
|
await Promise.all(contexts.map(ctx => ctx.watch()));
|
|
|
|
} else {
|
|
|
|
await Promise.all(contexts.map(async ctx => {
|
|
|
|
await ctx.rebuild();
|
|
|
|
await ctx.dispose();
|
|
|
|
}));
|
|
|
|
}
|