grunt-contrib-uglify icon indicating copy to clipboard operation
grunt-contrib-uglify copied to clipboard

Allow to customize the “sources” field in the sourcemaps.

Open stanch opened this issue 10 years ago • 4 comments

Currently the sources field in sourcemaps is always relative to the sources. In my case it looks somewhat ugly:

../../../../src/main/webapp/home/scripts/home.js

I’m including the sources with sourcesContent and not serving the actual sources (and if I were serving them, it wouldn’t be at that path...).

Is there an option to tweak that relative path? uglify.js mentions -p/--prefix, but as far as I can see it’s not available from this plugin. I also tried sourceMapRoot, but it did nothing.

My base setup is like this:

uglify: {
  options: {
    sourceMap: true,
    sourceMapIncludeSources: true,
    compress: true,
    mangle: true
  },
  build: {
    files: [{
      /* Minify all but vendor scripts */
      expand: true,
      cwd: 'src/main/webapp/home',
      src: ['scripts/**/*.js', '!scripts/vendor/**'],
      dest: 'target/grunt/home'
    }]
  }
}

stanch avatar Jan 08 '15 16:01 stanch

This feature might be useful yeah. A workaround right now is to write a simple task that does something like:

var updateMap = JSON.parse(fs.readFileSync(SOURCEMAP_PATH));
updateMap.sources = ['some-path.js'];
fs.writeFileSync(SOURCEMAP_PATH, JSON.stringify(updateMap));

vladikoff avatar Jan 08 '15 16:01 vladikoff

+1

monolithed avatar Jan 28 '15 23:01 monolithed

+1

derzwen avatar Feb 04 '15 11:02 derzwen

+1

sebastientromp avatar Apr 26 '17 07:04 sebastientromp