-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
the content of the output map file is as below:
{ "version":3, "sources":["resources/script/test.js"], "names":["myworld","tetststr","alert"], "mappings":"AAAA,QAASA,WACR,GAAIC,GAAW,aACfC,OAAMD", "file":"test.min.js.map", "sourceRoot":"resources/script/" }
but the value of the property 'sources'
is relative path.all I want it is just the file name 'test.js'.
how to configure this way using uglifyjs ?
my grunt task file is :
module.exports = function(grunt) {
var pkg = require('../package');
var fslib = require('fs');
var pathlib = require('path');
var UglifyJS = require("uglify-js");
grunt.registerTask('ef-copy-minify', 'minified and uglified js task', function(arg1, arg2) {
var srcRootPath = pathlib.join(pkg.templates.src, pkg.templates.js.src);
function explorer(srcpath) {
grunt.file.recurse(srcpath, function callback(abspath, rootdir, subdir, filename) {
var arr = filename.split('.');
// file extension name
var ext = arr[arr.length - 1];
// file name
arr = arr.slice(0, arr.length - 1);
var minifiedFileName = arr.join('.') + '.min.' + ext;
var minifiedFullFileName = abspath.replace(filename, arr.join('.') + '.min.' + ext);
// output map part - start
var ugContentObj = UglifyJS.minify(abspath, {
outSourceMap: minifiedFileName + ".map",
sourceMapUrl: minifiedFileName + ".map",
sourceRoot: abspath.replace(filename, '')
// sourceRoot: "localhost/resources/"
});
// output map part - end
console.log(abspath.replace(filename, ''));
grunt.file.write(minifiedFullFileName + ".map", ugContentObj.map);
grunt.file.write(minifiedFullFileName, ugContentObj.code);
});
};
explorer(srcRootPath);
});
};
`