This repository has been archived by the owner on Feb 6, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
build.mjs
59 lines (56 loc) · 1.97 KB
/
build.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { build } from "esbuild";
import alias from "esbuild-plugin-alias";
import swc from "@swc/core";
import { promisify } from "util";
import { exec as _exec } from "child_process";
import fs from "fs/promises";
import path from "path";
const exec = promisify(_exec);
const tsconfig = JSON.parse(await fs.readFile("./tsconfig.json"));
const aliases = Object.fromEntries(Object.entries(tsconfig.compilerOptions.paths).map(([alias, [target]]) => [alias, path.resolve(target)]));
const commit = (await exec("git rev-parse HEAD")).stdout.trim().substring(0, 7) || "custom";
try {
await build({
entryPoints: ["./src/entry.ts"],
outfile: "./dist/vendetta.js",
minify: true,
bundle: true,
format: "iife",
target: "esnext",
plugins: [
{
name: "swc",
setup: (build) => {
build.onLoad({ filter: /\.[jt]sx?/ }, async (args) => {
// This actually works for dependencies as well!!
const result = await swc.transformFile(args.path, {
jsc: {
externalHelpers: true,
},
env: {
targets: "defaults",
include: [
"transform-classes",
"transform-arrow-functions",
],
},
});
return { contents: result.code };
});
},
},
alias(aliases),
],
define: {
__vendettaVersion: `"${commit}"`,
},
footer: {
js: "//# sourceURL=Vendetta",
},
legalComments: "none",
});
console.log("Build successful!");
} catch (e) {
console.error("Build failed...", e);
process.exit(1);
}