What's the difference between concat and uglify and minify?

流过昼夜 提交于 2019-12-31 08:35:21

问题


What's the difference between concat, uglify, and minify tasks in grunt? I set up an uglify task for all of my site's javascript tasks, and it seemed to both minify and concatenate them. Grunt's site has a great description for how to configure each task, but it doesn't seem to explain what each task actually does.


回答1:


  • Concatenation is just appending all of the static files into one large file.

  • Minification is just removing unnecesary whitespace and redundant / optional tokens like curlys and semicolons, and can be reversed by using a linter.

  • Uglification is the act of transforming the code into an "unreadable" form, that is, renaming variables/functions to hide the original intent... It is, also, irreversable.




回答2:


Concatenation - Merges all the specified files to create a new single file.

Minification - It simply means all the unnecessary white spaces and redundant optional tokens will be removed.

Example - self.description = 'Hello' Minified version will be - self.description='Hello'

Uglification - It simply means converting the code in such a format that core logic can't be understand easily. To do the same it renames the variable and their references, it renames the parameter with shorter name etc.It simply obfuscate the business logic so that no one can easily understands it.

Example -

self.description = 'Hello';
function(self.description){}

Uglified version will be -

  j.description = 'Hello';
  function(j.description){}


来源:https://stackoverflow.com/questions/19694448/whats-the-difference-between-concat-and-uglify-and-minify

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!