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);