Fix postbuild esbuild resolution by using Vite

This commit is contained in:
Kamran Ahmed
2026-07-08 03:33:40 +01:00
parent c30fc8ec07
commit cbf719f87e
+8 -4
View File
@@ -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);