admin管理员组

文章数量:1305127

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?

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?

Share Improve this question asked Mar 16, 2016 at 14:02 Imraan KhanImraan Khan 3751 gold badge3 silver badges9 bronze badges 3
  • This is an interesting question. Can you provide a little context? Are you afraid someone else will reverse engineer your code? Are you trying to reverse engineer someone else's code? Have you lost the original files and are attempting to restore them from the minified versions? – JDB Commented Mar 16, 2016 at 14:08
  • Basically I want to generate some code on runtime. the final code might not include code from all files. And I also want to avoid running a minification of the final code – Imraan Khan Commented Mar 16, 2016 at 14:18
  • Then why bine the files in the first place? I think extracting code is going to be far more expensive then minifying it. If you minify each file individually, wouldn't that give you the best of both worlds? You can bine as needed without having to minify at runtime. – JDB Commented Mar 16, 2016 at 14:21
Add a ment  | 

1 Answer 1

Reset to default 11

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./hooptie45/6f9a7e6251a120c8d2d04e75f9d73c0e#file-sourcemap-extract-rb

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

本文标签: nodejsExtract individual javascript file code from minified fileStack Overflow