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?
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.
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.
ctrl-k, followed by ctrl-d. ctrl-e, followed by d.
Minification does improve performance for two reasons: Reduced file-size (because it removes comments and unnecessary white spaces), so your script loads faster.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With