A Grunt task originally by James Allardice to append a JavaScript sourcemapping URL comment
npm install grunt-append-sourcemappingurlgrunt-append-sourcemappingurl
==========================
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.
javascript
grunt.initConfig({
"closure-compiler": {
includeSourcemap: {
js: [
"inputFile.js",
"inputFile2.js"
],
jsOutputFile: "build/lib.min.js",
options: {
create_source_map: "build/lib.min.js.map",
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:
`javascript
grunt.loadNpmTasks("grunt-append-sourcemappingurl"); // Load the task
grunt.initConfig({
"closure-compiler": {
// Closure compiler configuration
},
"append-sourcemappingurl": {
main: {
files: {
"build/lib.min.js": "lib.min.js.map"
}
}
}
});
`
This will append the following comment to the end of lib.min.js:
`javascript
//# sourceMappingURL=lib.min.js.map
`
You can specify any number of files in the files` property, and as this is a Grunt multitask you can specify different targets too.