12

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?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Adarsha Beleyur
  • 157
  • 1
  • 1
  • 7

2 Answers2

12

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.

  • Thank you so much . Now i am getting – Adarsha Beleyur May 03 '18 at 11:37
  • 4
    unminifying can happen and is often useful in trying to debug minified Javascript code when you don't have the source. Just cause it's not optimal doesn't mean it can't be done. – thenetimp Mar 03 '20 at 15:28
  • 1
    @thenetimp I think the point is that variable names and function names are unrecoverable, so "unminifying" won't give you something as readable as the source code. To me, it's all linguistic, people probably mean beautify" when they say unminify. – Att Righ Jul 31 '22 at 14:29
7

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.

Ali Kazemkhanloo
  • 1,017
  • 1
  • 10
  • 16