diff --git a/build.mjs b/build.mjs index 102e9cd..827bf44 100644 --- a/build.mjs +++ b/build.mjs @@ -1,51 +1,58 @@ +import { build } from "esbuild"; +import { replace } from "esbuild-plugin-replace"; +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 { 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"; - +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 { - const bundle = await rollup({ - input: "src/index.ts", - onwarn: () => {}, - plugins: [ - 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 }), - ], - }); - - await bundle.write({ + await build({ + entryPoints: ["./src/index.ts"], + outfile: "./dist/vendetta.js", + minify: true, + bundle: true, format: "iife", - file: "dist/vendetta.js", - compact: true, + 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), + replace({ + "__vendettaVersion": commit, + }), + ], + legalComments: "none", }); - await bundle.close(); await fs.appendFile("./dist/vendetta.js", "//# sourceURL=Vendetta"); console.log("Build successful!"); } catch (e) { console.error("Build failed...", e); process.exit(1); -} +} \ No newline at end of file diff --git a/package.json b/package.json index 6cb7f00..dab3fb2 100644 --- a/package.json +++ b/package.json @@ -15,20 +15,17 @@ "license": "BSD-3-Clause", "devDependencies": { "@react-native-clipboard/clipboard": "1.10.0", - "@rollup/plugin-node-resolve": "^15.0.1", - "@rollup/plugin-replace": "^5.0.2", "@swc/core": "^1.3.35", "@types/react": "18.0.27", "@types/react-native": "0.70.6", - "esbuild": "^0.17.10", + "esbuild": "^0.17.11", + "esbuild-plugin-alias": "^0.2.1", + "esbuild-plugin-replace": "^1.3.0", "moment": "2.22.2", - "rollup": "^3.17.1", - "rollup-plugin-esbuild": "^5.0.0", - "rollup-plugin-swc3": "^0.8.0", - "rollup-plugin-typescript-paths": "^1.4.0", "typescript": "^4.9.5" }, "dependencies": { + "@swc/helpers": "^0.4.14", "spitroast": "^1.4.2" }, "pnpm": {