Grunt Uglify - How to create a source map for debugging?

lol picture lol · Oct 22, 2013 · Viewed 9.2k times · Source

I'm using grunt in a project and created tasks to minify and concat many .js files.

I'm now trying to figure out how to create a source map out of them with Uglify so the other team can easily analyze the code in the console.

Part of my Gruntfile (in coffee) looks like these two:

        uglify:
        options:
            mangle: false

/

    grunt.registerTask 'devmin', ['clean', 'concurrent:transform', 'useminPrepare', 'concat', 'uglify', 'usemin', 'copy:build', 'server', 'watch:dist'] # Dev - minifies files

So, when I run "grunt devmin" on terminal I'll have minified versions but I can't figure out how to create a related sourcemap to them for debugging purposes.

Anyone's got a hint??

Thank you!

Answer

Dan picture Dan · Oct 22, 2013

There are various source map properties on the options object that you can set.

You probably want the "sourceMap" property, which is the file name of the source map to output e.g.

    uglify:
        options:
            sourceMap: 'mymap.map'

sourceMap can also be a function, where the first parameter is the output path of the file that you are minifying.