混淆
🌐 Mangling
Oxc 压缩器支持混淆变量名称和私有类字段。
🌐 Oxc minifier supports mangling variable names and private class fields.
此功能默认启用,可以通过将 mangle 选项设置为 false 来禁用。
🌐 This feature is enabled by default and can be disabled by setting the mangle option to false.
顶层变量
🌐 Top Level Variables
默认情况下,顶层变量对于非模块代码不会被混淆。你可以通过将 mangle.toplevel 选项设置为 true 来启用顶层变量的混淆。
🌐 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.
// input
var foo = 1;
// output
var e = 1;// Example
import { minify } from "oxc-minify";
const result = await minify("lib.js", code, {
module: false, // non-module code
compress: {
mangle: {
toplevel: true,
},
},
});保留 name 属性值
🌐 Keep name Property Values
混淆变量名可能会更改函数/类的 name 属性值。通过启用 mangle.keepNames 选项,你可以保留原始的 name 属性值。
🌐 Mangling variable names can change the name property values of functions / classes. You can keep the original name property values by enabling the mangle.keepNames option.
// input
var foo = function () {};
// output
var foo = function () {};// Example
import { minify } from "oxc-minify";
const result = await minify("lib.js", code, {
compress: {
mangle: {
keepNames: true, // shorthand of { function: true, class: true }
},
},
});compress.keepNames 选项
启用此选项时,你可能还想启用‘compress.keepNames’选项。
🌐 When enabling this option, you may also want to enable the compress.keepNames option.
调试碎纸机
🌐 Debugging The Mangler
要调试混淆器,你可以启用 mangle.debug 选项。启用此选项后,混淆器将使用 slot_0、slot_1 等作为变量名。
🌐 To debug the mangler, you can enable the mangle.debug option. When this option is enabled, the mangler will use slot_0, slot_1, ... as variable names.
// input
var foo = 1;
// output
var slot_0 = 1;// Example
import { minify } from "oxc-minify";
const result = await minify("lib.js", code, {
compress: {
mangle: {
debug: true,
},
},
});