I am using UglifyJS2 to minify my javascript source files into one large minified file. Here is the relevant bit of code that I use:
var options = options || {};
options.outSourceMap = 'minfile.js.map';
try {
// "scripts" is an array of absolute paths to the javascript files
var minified = uglifyjs.minify(scripts, options);
// minified.map contains the minfile
} catch (err) {
// handle errs here
}
The minfile itself contains absolute paths to the source files:
{
"version": 3,
"file": "nodebb.min.js.map",
"sources": [
"/path/to/folder/jquery/js/jquery.js",
"/path/to/folder/another/lib.js",
...
],
...
}
The problem is, the source files I'm passing in are not accessible publically, they are only compiled into the minfile and only the minfile is accessible. Therefore, my source map seems to be pointless, as Chrome (in my case) tries to load http://mydomain.com/path/to/folder/jquery/js/jquery.js
instead of reading the file on my local fs.
What am I doing wrong?
Looks like the
UglifyJS2
repo is missing a bunch of options for the node API, but this PR fixed it up a bit: https://github.com/mishoo/UglifyJS2/pull/192So I'm using that in my
package.json
now:Then
prefix
can be passed into theminify
method to lop off parts of the path that aren't needed.