Skip to content

Persist esbuild.mangleCache between builds #20692

@hades343

Description

@hades343

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions