[Build] Fix ErrorBoundary exporting (#30)

This commit is contained in:
redstonekasi 2023-03-07 01:23:16 +01:00 committed by GitHub
parent dc5ad0ca1f
commit 3531132c38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 43 deletions

View file

@ -1,29 +1,35 @@
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: () => {},
await build({
entryPoints: ["./src/index.ts"],
outfile: "./dist/vendetta.js",
minify: true,
bundle: true,
format: "iife",
target: "esnext",
plugins: [
replace({
__vendettaVersion: commit,
preventAssignment: true,
}),
typescriptPaths(),
nodeResolve({ extensions: [".tsx", ".ts", ".jsx", ".js", ".json"] }),
swc({
{
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: [
@ -31,18 +37,19 @@ try {
"transform-arrow-functions",
],
},
});
return { contents: result.code };
});
},
},
alias(aliases),
replace({
"__vendettaVersion": commit,
}),
esbuild({ minify: true }),
],
legalComments: "none",
});
await bundle.write({
format: "iife",
file: "dist/vendetta.js",
compact: true,
});
await bundle.close();
await fs.appendFile("./dist/vendetta.js", "//# sourceURL=Vendetta");
console.log("Build successful!");
} catch (e) {

View file

@ -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": {