最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How should I use mangle option in uglifyjs? - Stack Overflow

programmeradmin0浏览0评论

When running the following command:

echo "let demo = 3; console.log(demo);" | uglifyjs --compress --mangle

I would expect the following output:

let a=3;console.log(a);

Instead, I get:

let demo=3;console.log(demo);

Therefore, I don't understand how I should use --mangle option. The official documentation explains how to exclude the names which shouldn't be mangled, how to mangle properties, etc., but how do I just transform the names of ordinary variables?

Or is this option doing something completely different, and I misunderstood its purpose?

Note: I'm using uglify-es 3.2.2.

When running the following command:

echo "let demo = 3; console.log(demo);" | uglifyjs --compress --mangle

I would expect the following output:

let a=3;console.log(a);

Instead, I get:

let demo=3;console.log(demo);

Therefore, I don't understand how I should use --mangle option. The official documentation explains how to exclude the names which shouldn't be mangled, how to mangle properties, etc., but how do I just transform the names of ordinary variables?

Or is this option doing something completely different, and I misunderstood its purpose?

Note: I'm using uglify-es 3.2.2.

Share Improve this question asked Dec 29, 2017 at 17:03 Arseni MourzenkoArseni Mourzenko 52.3k35 gold badges118 silver badges210 bronze badges 2
  • did you try "uglifyjs --compress --mangle --toplevel" ? should mangle everything in the top level scope – MercyDude Commented Dec 29, 2017 at 17:23
  • 2 @MercyDude: nice! Please, post it as an answer so I can accept it. – Arseni Mourzenko Commented Dec 29, 2017 at 17:36
Add a comment  | 

1 Answer 1

Reset to default 16

So I looked at The official documentation, and as you said --mangle is the option where you choose what not to mangle (how convenient), and figured out that you should use --toplevel which mangle everything in the top level scope.

Eventually it should look like that:

uglifyjs --compress --mangle --toplevel

发布评论

评论列表(0)

  1. 暂无评论