mirror of
https://github.com/kamranahmedse/driver.js.git
synced 2026-10-31 03:52:13 +08:00
Minify the ESM bundle whitespace in postbuild
This commit is contained in:
+10
-1
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user