Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
[FEATURE] Override sourceMappingURL with custom function (Closes #24)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjonuschat committed Jul 29, 2014
1 parent 9e428c3 commit 83b6970
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -73,6 +73,10 @@ CSS compression function or predefined `mincer` css compressor identifier `"csso

The base url to use when referencing source-maps in compiled assets. Defaults to `""` if not explicitly set.

#### sourceMappingURL ```function(options, file)```

Optional function that is called to determine the sourceMappingURL for a file. Has access to the grunt task options as well as the file object for current asset. By default returns the destination filename prefixed with the `sourceMappingBaseURL`

### Files

The files on which the task operates can be defined using all the powerful options provided by Grunt.
Expand Down
5 changes: 3 additions & 2 deletions tasks/lib/helpers.js
Expand Up @@ -177,10 +177,11 @@ exports.init = function (grunt) {
});

if([].concat(options.enable).indexOf('source_maps') > -1) {
var mapUrl = options.sourceMappingURL(options, file);
if (/\.css$/.test(file.dest)) {
sourceNode.add('/*# sourceMappingURL=' + options.sourceMappingBaseURL + file.dest + '.map' + ' */');
sourceNode.add('/*# sourceMappingURL=' + mapUrl + ' */');
} else {
sourceNode.add('//# sourceMappingURL=' + options.sourceMappingBaseURL + file.dest + '.map');
sourceNode.add('//# sourceMappingURL=' + mapUrl);
}
}

Expand Down
1 change: 1 addition & 0 deletions tasks/mincer.js
Expand Up @@ -23,6 +23,7 @@ module.exports = function (grunt) {
embedMappingComments: true
},
sourceMappingBaseURL: '',
sourceMappingURL: function (options, file) { return options.sourceMappingBaseURL + file.dest + '.map' },
helpers: {},
engines: {},
jsCompressor: null,
Expand Down

0 comments on commit 83b6970

Please sign in to comment.