맹글링
Oxc 미니파이어는 변수 이름과 비공개 클래스 필드 맹글링을 지원합니다.
기본으로 켜져 있으며 mangle 옵션을 false로 두면 끌 수 있습니다.
최상위 변수
모듈이 아닌 코드에서는 최상위 변수는 기본적으로 맹글링하지 않습니다. mangle.toplevel을 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,
},
},
});name 속성 값 유지
변수 이름을 맹글링하면 함수·클래스의 name 속성 값이 바뀔 수 있습니다. mangle.keepNames를 켜면 원래 name 값을 유지합니다.
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 }
},
},
});compress.keepNames 옵션
이 옵션을 켤 때는 compress.keepNames 옵션도 함께 켜는 것이 좋습니다.
맹글러 디버깅
맹글러를 디버깅하려면 mangle.debug를 켭니다. 켜면 맹글러가 변수 이름으로 slot_0, slot_1, …를 사용합니다.
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,
},
},
});