Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Revert JavaScript minification using source map

Tags:

javascript

Is it possible to get a proper JavaScript source file if I have the minified file and its corresponding source map?

I know how to prettify JS code (line-breaks and indents), but I would like to get original function / variable names in the file, to be able to better understand the source code.

I would like to get the un-minified JS file to work with, instead of using it to debug in a browser.

PS It is probably somewhere right under my nose, but I didn't manage to find it so far. Sorry if this was already asked!

like image 964
NPC Avatar asked Jun 08 '15 23:06

NPC


1 Answers

To work sourcemaps requires both files, minified and original, often original is included in sourcemap file(it has optional sourcesContent for sources that can not be hosted).

Sourcemap is just JSON file, and you can found all needed information inside:

  • sources - list of source file names,
  • sourcesContent - optional list of original sources, if source is not presented it would be null here.

Utility script, I have written before for this purpose: https://gist.github.com/zxbodya/ca6fb758259f6a077de7

like image 55
Bogdan Savluk Avatar answered Oct 07 '22 16:10

Bogdan Savluk