Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify multiple source-maps in uglify grunt task?

I am using grunt-contrib-uglify plugin in my grunt 0.4.

I have the following task:

uglify: {
  dist: {
    options: {
      sourceMap: 'dist/sm/sm.js'
    },
    files: grunt.file.expandMapping(['*.js'], 'dist/js', {
      cwd: 'dist/js'
    })
  }
},

As you can see, uglify is configured to compress multiple files, and there is only one source-map specified. (I am not able to figure out a way to specify multiple sourcemap outputs).

Also, uglify is overwriting the soucemap after compressing each js file.

How do I configure this plugin to output the complete source-maps for all my js files?

like image 630
Niyaz Avatar asked Jan 08 '13 03:01

Niyaz


2 Answers

You can set functtion at sourceMap.

uglify: {
  options: {
      sourceMap: function(path) { return path.replace(/.js/,".map")} 
  },
  .....
like image 192
panghea Avatar answered Oct 03 '22 09:10

panghea


In the V0.4.0 version, sourceMap is Boolean value. Use dynamic build to produce multiple sourceMap with multiple .min.js files.

uglify: {
  options: {
    sourceMap: true
  },
  build: {
    files: [{
        expand: true,
        cwd: 'src/',
        src: '*.js',
        dest: 'build/',
        ext: '.min.js',
        extDot: 'first'
    }]
  }
}
like image 45
Kamel Avatar answered Oct 03 '22 10:10

Kamel