import * as esbuild from "npm:esbuild";
import { denoPlugins } from "jsr:@luca/esbuild-deno-loader";
import browserslist from "npm:browserslist";
import { projectRootDir } from "../root.ts";

const browsers = browserslist([
	"last 4 Chrome versions",
	"last 4 Edge versions",
	"last 4 Opera versions",
	"last 4 Firefox versions",
	"last 4 Safari versions",
]).map((browser: string) => browser.replace(" ", ""));

// esbuild target is fine-grained: https://esbuild.github.io/api/#target
const target = [...browsers, "ios18", "ios17", "ios16", "ios14"];
await esbuild.build({
	plugins: [...denoPlugins()],
	absWorkingDir: projectRootDir,
	entryPoints: ["src/client/index.tsx"],
	outfile: "static/dist/bundle.js",
	bundle: true,
	format: "esm",
	target,
	jsx: "automatic",
	jsxImportSource: "react",
});

esbuild.stop();
