How to unminify the js files?

与世无争的帅哥 提交于 2020-06-17 13:09:07

问题


How can I unminify js file which is minify from webpack tool.

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?

I want minified js file back into original format.

Can anyone tell me the tools or way to unminify the js file?

Thank you.


回答1:


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 beautifier to make it more readable, but you will have a weighty job of reverse engineering in order to understand what the code means.




回答2:


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).

Then using source-map library you can recover the original files.

If the source-map file does include the minified source, this file is enough to unminify. otherwise, you have to tell the library the minified source manually.

More info, on the library's Github page.



来源:https://stackoverflow.com/questions/50153889/how-to-unminify-the-js-files

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