diff --git a/scripts/postbuild.mjs b/scripts/postbuild.mjs index 68a967a..eb400aa 100644 --- a/scripts/postbuild.mjs +++ b/scripts/postbuild.mjs @@ -1,4 +1,5 @@ -import { copyFileSync } from "node:fs"; +import { copyFileSync, readFileSync, writeFileSync } from "node:fs"; +import { transform } from "esbuild"; // vite-plugin-dts emits a single bundled declaration file. Copy it to the // ESM/CJS-specific extensions so each `exports` condition resolves to types @@ -6,3 +7,11 @@ import { copyFileSync } from "node:fs"; const source = "dist/driver.js.d.ts"; copyFileSync(source, "dist/driver.js.d.mts"); copyFileSync(source, "dist/driver.js.d.cts"); + +// Vite 8 whitespace-minifies the CJS and IIFE outputs but ships the ESM bundle +// with its whitespace intact, so run a final esbuild pass on just the .mjs to +// strip it (~9% smaller gzipped). Identifiers are already mangled and no +// sourcemaps are shipped, so there is no downside for consumers. +const esmBundle = "dist/driver.js.mjs"; +const minified = await transform(readFileSync(esmBundle, "utf8"), { minify: true, legalComments: "none" }); +writeFileSync(esmBundle, minified.code);