From cbf719f87efc608a562aedd2404b179d8419ba0e Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Wed, 8 Jul 2026 03:33:40 +0100 Subject: [PATCH] Fix postbuild esbuild resolution by using Vite --- scripts/postbuild.mjs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/postbuild.mjs b/scripts/postbuild.mjs index a98bb1d..22ae7b1 100644 --- a/scripts/postbuild.mjs +++ b/scripts/postbuild.mjs @@ -1,5 +1,5 @@ import { copyFileSync, readFileSync, writeFileSync } from "node:fs"; -import { transform } from "esbuild"; +import { transformWithEsbuild } from "vite"; // vite-plugin-dts emits a single bundled declaration file. Copy it to the // ESM/CJS-specific extensions so each `exports` condition resolves to types @@ -9,7 +9,11 @@ copyFileSync(source, "dist/driver.js.d.mts"); copyFileSync(source, "dist/driver.js.d.cts"); // Vite ships the ESM bundle with its whitespace intact (the CJS and IIFE builds -// are already minified), so strip it here for a smaller gzipped file. +// are already minified), so strip it here for a smaller gzipped file. Reuses +// Vite's own esbuild so the build pulls in no extra dependency. const esmBundle = "dist/driver.js.mjs"; -const minified = await transform(readFileSync(esmBundle, "utf8"), { minify: true, legalComments: "none" }); -writeFileSync(esmBundle, minified.code); +const { code } = await transformWithEsbuild(readFileSync(esmBundle, "utf8"), esmBundle, { + minify: true, + legalComments: "none", +}); +writeFileSync(esmBundle, code);