Revenge/build.mjs

52 lines
1.5 KiB
JavaScript
Raw Normal View History

2023-01-10 23:30:46 +00:00
import { promisify } from "util";
import { exec as _exec } from "child_process";
2022-10-18 22:04:55 +00:00
import fs from "fs/promises";
import { rollup } from "rollup";
import { swc } from "rollup-plugin-swc3";
import { typescriptPaths } from "rollup-plugin-typescript-paths";
import esbuild from "rollup-plugin-esbuild";
import replace from "@rollup/plugin-replace";
import nodeResolve from "@rollup/plugin-node-resolve";
const exec = promisify(_exec);
2023-01-10 23:30:46 +00:00
const commit = (await exec("git rev-parse HEAD")).stdout.trim().substring(0, 7) || "custom";
2022-10-18 22:04:55 +00:00
try {
const bundle = await rollup({
input: "src/index.ts",
onwarn: () => {},
plugins: [
2023-01-10 23:30:46 +00:00
replace({
__vendettaVersion: commit,
preventAssignment: true,
}),
typescriptPaths(),
nodeResolve({ extensions: [".tsx", ".ts", ".jsx", ".js", ".json"] }),
swc({
env: {
targets: "defaults",
include: [
"transform-classes",
"transform-arrow-functions",
],
},
}),
esbuild({ minify: true }),
],
2022-10-18 22:04:55 +00:00
});
await bundle.write({
format: "iife",
file: "dist/vendetta.js",
compact: true,
});
await bundle.close();
2022-10-18 22:04:55 +00:00
await fs.appendFile("./dist/vendetta.js", "//# sourceURL=Vendetta");
console.log("Build successful!");
} catch (e) {
console.error("Build failed...", e);
process.exit(1);
}