Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract individual javascript file code from minified file

I have a list of .js files and I have a single minified version of these files with the source map. The minified file has been created using UglifyJS

Is it possible to extract code of the individual js files from the minified file? maybe by reading the source map?

eg:

original files:
1)head.js
2)tail.js
3)stomach.js
4)liver.js

minified file (containing code of all of above files):
-> body.min.js

source map:
-> body.min.js.map

Is it possible to extract the minified code (string) of stomach.js from body.min.js?

like image 805
Imraan Khan Avatar asked Mar 16 '16 14:03

Imraan Khan


People also ask

How extract minified JS file?

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.

Can you un minify JavaScript?

Sometimes, the JavaScript code that runs on a website is minified and really hard to read. This is common in production. You can unminify code in DevTools to read it more easily, and also set breakpoints.

How do I Unminify JavaScript code in Visual Studio?

ctrl-k, followed by ctrl-d. ctrl-e, followed by d.

Is minified JavaScript faster?

Minification does improve performance for two reasons: Reduced file-size (because it removes comments and unnecessary white spaces), so your script loads faster.


1 Answers

This script will expand minified source (via give sourcemap), and recreate all the files; essentially mirroring the original source repo. Is this what you needed? Quick and dirty, but might do the trick. (only tested against sourcemaps derived from webpack)

https://gist.github.com/hooptie45/6f9a7e6251a120c8d2d04e75f9d73c0e#file-sourcemap-extract-rb

$ ./sourcemap-extract.rb site.com/assets/app.min.js.map ./tmp

like image 60
user407275 Avatar answered Sep 21 '22 01:09

user407275