-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Description
Description
When using Vite with esbuild minifier with property mangling, there’s no way to persist esbuild’s mangleCache across builds. esbuild returns an updated mangleCache on the result object. Vite doesn’t expose that result to userland and doesn’t mutate the object passed in via config. Outcome: the user-provided mangleCache stays empty/unchanged, making cross-build consistency impossible. Practically, mangleCache is useless in this flow right now.
Repro
import { defineConfig } from "vite";
const __cache__ = {};
export default defineConfig({
plugins: [
{
name: "repro",
apply: "build",
closeBundle() {
console.log(structuredClone(__cache__)); // always empty object since esbuild doesn't mutate args
},
},
],
build: {
minify: "esbuild",
},
esbuild: {
minifyIdentifiers: true,
mangleCache: __cache__,
mangleProps: /.+/, // since this matches all props, __cache__ shouldn't be empty
mangleQuoted: true,
},
});
Suggested solution
Vite exposes esbuild’s returned mangleCache so userland can persist it.
Alternative
Vite ensures the provided mangleCache object is updated (mutated) with esbuild’s results.
Additional context
The whole point of mangleCache is cross-build determinism and compatibility across separately built chunks/packages. Without persistence, property mangling can break consumers or produce inconsistent artifacts.
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.