Skip to content

how to configure using uglifyjs to set property of 'sources' from a map file to be just src js file name rather than its relative path #1359

@enforceway

Description

@enforceway

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);
});

};
`

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions