Grunt task to append sourcemapping URL comments to JavaScript files
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


A Grunt task to append JavaScript sourcemapping URL comments to files. The Google Closure Compiler does not currently append the necessary sourcemapping URL comment to the output it produces, even when you ask it to generate a source map with the create_source_map option. This Grunt plugin will add that comment for you.


Just install via npm like usual:

npm install grunt-append-sourcemapping


This task assumes that you are using the Closure Compiler to handle JavaScript minification and source map generation. Chances are, you're using the grunt-closure-compiler plugin to do that, so you'll probably have a task in your Grunt file that looks something like this:

    "closure-compiler": {
        includeSourcemap: {
            js: [
            jsOutputFile: "build/lib.min.js",
            options: {
                create_source_map: "build/",
                source_map_format: "V3"

To append a sourcemapping URL comment at the end of the minified file, you need to tell Grunt to load the new task and then add another section to your config:

grunt.loadNpmTasks("grunt-append-sourcemapping"); // Load the task
    "closure-compiler": {
        // Closure compiler configuration
    "append-sourcemapping": {
        main: {
            files: {
                "build/lib.min.js": ""

This will append the following comment to the end of lib.min.js (see this jQuery bug ticket for full details on why the wrapping multiline comment is necessary - in short, it's a workaround for an Internet Explorer issue):


You can specify any number of files in the files property, and as this is a Grunt multitask you can specify different targets too.