Skip to content

Mangling

Oxc minifier supports mangling variable names and private class fields.

This feature is enabled by default and can be disabled by setting the mangle option to false.

Top Level Variables

Top level variables are not mangled by default for non module code. You can enable mangling for top level variables by setting the mangle.toplevel option to true.

js
// input
var foo = 1;

// output
var e = 1;
``````js
// Example
import { minify } from "oxc-minify";

const result = await minify("lib.js", code, {
  module: false, // non-module code
  compress: {
    mangle: {
      toplevel: true,
    },
  },
});
``````js
// input
var foo = function () {};

// output
var foo = function () {};
``````js
// Example
import { minify } from "oxc-minify";

const result = await minify("lib.js", code, {
  compress: {
    mangle: {
      keepNames: true, // shorthand of { function: true, class: true }
    },
  },
});
``````js
// input
var foo = 1;

// output
var slot_0 = 1;
``````js
// Example
import { minify } from "oxc-minify";

const result = await minify("lib.js", code, {
  compress: {
    mangle: {
      debug: true,
    },
  },
});