[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,47 +1,54 @@
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 { promisify } from "util";
import { exec as _exec } from "child_process"; import { exec as _exec } from "child_process";
import fs from "fs/promises"; import fs from "fs/promises";
import path from "path";
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); 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"; const commit = (await exec("git rev-parse HEAD")).stdout.trim().substring(0, 7) || "custom";
try { try {
const bundle = await rollup({ await build({
input: "src/index.ts", entryPoints: ["./src/index.ts"],
onwarn: () => {}, outfile: "./dist/vendetta.js",
plugins: [ minify: true,
replace({ bundle: true,
__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({
format: "iife", format: "iife",
file: "dist/vendetta.js", target: "esnext",
compact: true, 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"); await fs.appendFile("./dist/vendetta.js", "//# sourceURL=Vendetta");
console.log("Build successful!"); console.log("Build successful!");

View file

@ -15,20 +15,17 @@
"license": "BSD-3-Clause", "license": "BSD-3-Clause",
"devDependencies": { "devDependencies": {
"@react-native-clipboard/clipboard": "1.10.0", "@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", "@swc/core": "^1.3.35",
"@types/react": "18.0.27", "@types/react": "18.0.27",
"@types/react-native": "0.70.6", "@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", "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" "typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@swc/helpers": "^0.4.14",
"spitroast": "^1.4.2" "spitroast": "^1.4.2"
}, },
"pnpm": { "pnpm": {