简体   繁体   中英

Why do minfiers reduce to one line

This question is similar to: Why do we have newlines in minified JavaScript?

In this case, I would prefer half a dozen or so newlines. Why do minifiers reduce code and style to one line? Even on production code, I might have bugs that I didn't consider. While, other may be professional-100% perfect developers, I'd like an option to at least insert a dozen or so newlines. I have avoided minifying code for a bit. Until now, I'd like a bit more performance but some balance of code review as well.

Maybe not a newline for every function, but at least for every class object since I use a lot of custom React Component classes.

Pretty:

var num = 10;
const dothis = function() {
 let x = 0;
 for(x = 0; x < num; x++) {
    ...
};
function dothat(){
  var foo = 'Hello';
  let name = 'World';
  var bar = foo + name;
  console.log(bar);
}

Uglified

var num=10;const dothis=function(){let x=0;for(x=0;x<num;x++){...}};function dothat(){var foo = 'Hello';let name = 'World';var bar = foo + name;console.log(bar);}

Something in between

var num = 10;
const dothis = function() { let x=0; for(x = 0; x < num; x++) {...};
function dothat(){ var foo = 'Hello'; let name = 'World'; var bar = foo + name; console.log(bar); }

Having half a dozen or so newline would allow me to narrow down the function or class causing the problem. I understand this shouldn't replace testing during development.

Use the pretty-print option in devtools.

在此处输入图片说明

This will give you:

在此处输入图片说明

Documentation is here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM