mirror of
https://github.com/kamranahmedse/driver.js.git
synced 2026-10-31 03:52:13 +08:00
Fix postbuild esbuild resolution by using Vite
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user