语法规范化
🌐 Syntax Normalization
Oxc 压缩器支持转换语法以使输出更简短和重复的部分更少。
🌐 Oxc minifier supports transforming syntaxes to make the output shorter and repetitive.
此功能默认启用,可以通过将 compress 选项设置为 false 来禁用。
🌐 This feature is enabled by default and can be disabled by setting the compress option to false.
目标
🌐 Target
Oxc 压缩器使用了一些仅在较新环境中支持的语法。你可以通过设置 target 选项来指定目标环境。默认值是 esnext,该值允许使用最新 ECMAScript 标准支持的任何语法。支持的值与转换器中的 target 选项相同。
🌐 Oxc minifier uses some syntaxes that are only supported in newer environments. You can specify the target environment by setting the target option. The default value is esnext, which allows the use of any syntaxes that are supported by the latest ECMAScript standard. The supported value is same as the target option in the transformer.
import { minify } from "oxc-minify";
const result = await minify("lib.js", code, {
compress: {
target: "chrome87",
},
});连接变量
🌐 Join Variables
默认情况下,连续的变量声明会合并为一个声明。你可以通过将 compress.joinVars 选项设置为 false 来禁用此行为。
🌐 By default, consecutive variable declarations are merged into a single declaration. You can disable this behavior by setting the compress.joinVars option to false.
// input
var foo = 1;
var bar = 2;
// output
var foo = 1,
bar = 2;// Example
import { minify } from "oxc-minify";
const result = await minify("lib.js", code, {
compress: {
joinVars: false,
},
});序列
🌐 Sequences
默认情况下,连续的语句会使用逗号运算符合并为一个语句。你可以通过将 compress.sequences 选项设置为 false 来禁用此行为。
🌐 By default, consecutive statements are merged into a single statement using the comma operator. You can disable this behavior by setting the compress.sequences option to false.
// input
foo();
bar();
// output
(foo(), bar());// Example
import { minify } from "oxc-minify";
const result = await minify("lib.js", code, {
compress: {
sequences: false,
},
});