常见问题
🌐 FAQ
顶层变量已被移除
🌐 Top level variables are removed
当源类型为 module 时,顶层变量会被移除。这是因为模块代码中的顶层变量无法被其他模块访问。与此相反,脚本代码中的顶层变量被视为全局变量,可以被其他脚本访问。如果你希望保留顶层变量,则不应使用 .mjs 文件名,也不应启用 module 选项。
🌐 Top level variables are removed when the source type is module. This is because top level variables in module code are not accessible from other modules. Contrary to that, top level variables in script code are treated as global variables and are accessible from other scripts. If you expect the top level variables to be kept, you should not use a .mjs filename nor enable the module option.
字符串中的新行不会被移除
🌐 New lines in strings are not removed
令人惊讶的是,在压缩代码中,字符串中的新行不会被移除并替换为 \n。这种行为的原因是字符转义序列 \n 是两个字节长,而换行符是一个字节长。
🌐 It may be surprising that new lines in strings are not removed and replaced with \n in minified code. This behavior is because the character escape sequences \n is two bytes long while the new line character is one byte long.
// this code is 16 bytes
const foo="a\nb"
// this code is 15 bytes
const foo=`a
b`