javascript 如何取消压缩js文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50153889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to unminify the js files?
提问by Adarsha Beleyur
How can I unminify js file which is minify from webpack tool.
如何取消从 webpack 工具缩小的 js 文件。
Before minify,
在缩小之前,
function autoslideSlider() {
$('.next-slide').trigger('click');
}
$(window).on('load', function(){
$('.preloader').fadeOut('fast');
$('#after_load').addClass('show');
setInterval(autoslideSlider, 8000);
});
$('a').on('click', function () {
if (location.pathname.replace(/^\//, '') === this.pathname.replace(/^\//, '') && location.hostname === this.hostname) {
var $target = $(this.hash);
$target = $target.length && $target;
// $('[name=' + this.hash.slice(1) + ']');
if ($target.length) {
var targetOffset = $target.offset().top - 20;
$('html,body').animate({
scrollTop: targetOffset
}, 1500);
return false;
}
}
});
After minify,
缩小后,
!function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:o})},n.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t){function n(){$(".next-slide").trigger("click")}$(window).on("load",function(){$(".preloader").fadeOut("fast"),$("#after_load").addClass("show"),setInterval(n,8e3)}),$("a").on("click",function(){if(location.pathname.replace(/^\//,"")===this.pathname.replace(/^\//,"")&&location.hostname===this.hostname){var e=$(this.hash);if((e=e.length&&e).length){var t=e.offset().top-20;return $("html,body").animate({scrollTop:t},1500),!1}}})}]);
How can I unminify the above js file?
我怎样才能取消上面的js文件?
I want minified js file back into original format.
我想将缩小的 js 文件恢复为原始格式。
Can anyone tell me the tools or way to unminify the js file?
谁能告诉我取消压缩 js 文件的工具或方法?
Thank you.
谢谢你。
回答by Cristian Traìna
You can't unminify a minified file. Minification is a desctructive operation and involves loss of information.
您无法取消缩小缩小的文件。缩小是一种破坏性操作,涉及信息丢失。
For example, if you have a function with a descriptive name, after minifcation that name will be substitute with a meaningless one. There's no way to go back from this operation.
例如,如果您有一个具有描述性名称的函数,则在缩小后该名称将被替换为无意义的名称。没有办法从这次行动中回来。
You can use a beautifierto make it more readable, but you will have a weighty job of reverse engineering in order to understand what the code means.
您可以使用美化器使其更具可读性,但是为了理解代码的含义,您将有一项繁重的逆向工程工作。
回答by Ali Kazemkhanloo
source-maps are what you want. in the process of making a minified js file, you should get a source-map file, too (it depends on what tool you use for minification).
源映射就是你想要的。在制作一个缩小的 js 文件的过程中,你也应该得到一个 source-map 文件(这取决于你使用什么工具进行缩小)。
Then using source-maplibrary you can recover the original files.
然后使用源映射库您可以恢复原始文件。
If the source-mapfile does include the minified source, this file is enough to unminify. otherwise, you have to tell the library the minified source manually.
如果source-map文件确实包含缩小的源,则该文件足以取消缩小。否则,您必须手动告诉库缩小的源。
More info, on the library's Github page.
更多信息,在图书馆的 Github 页面上。
回答by Mohandas P G
If you want to reformat the web elements like HTML, CSS or Javascript, you can use the Unminifyor Unminify Jsonline tool and make desirable changes in your codes.
如果您想重新格式化 HTML、CSS 或 Javascript 等 Web 元素,您可以使用Unminify或Unminify Js在线工具并在您的代码中进行所需的更改。
回答by TheAlbear
There is a tool online that will allow you to do this.
有一个在线工具可以让您做到这一点。
But as stated by Archer, anything obfuscated will remain.
但正如 Archer 所说,任何混淆的东西都会保留下来。

