Skip to content

Commit c81d284

Browse files
montmanuXhmikosR
authored andcommitted
accept a function for sourceMapURL (#307)
1 parent e0c3722 commit c81d284

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

Gruntfile.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ module.exports = function(grunt) {
155155
src: 'test/fixtures/style3.less',
156156
dest: 'tmp/sourceMapWithCustomURL.css'
157157
},
158+
sourceMapURLFunction: {
159+
options: {
160+
sourceMap: true,
161+
sourceMapFilename: 'tmp/maps/sourceMapURLFunction.css.map',
162+
sourceMapURL: function (/* dest */) {
163+
return '../maps/sourceMapURLFunction.css.map';
164+
}
165+
},
166+
src: 'test/fixtures/style3.less',
167+
dest: 'tmp/sourceMapURLFunction.css'
168+
},
158169
sourceMapBasepath: {
159170
options: {
160171
sourceMap: true,

tasks/less.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ module.exports = function(grunt) {
126126
}
127127
}
128128

129+
if (typeof options.sourceMapURL === 'function') {
130+
try {
131+
options.sourceMapURL = options.sourceMapURL(destFile);
132+
} catch (e) {
133+
grunt.fail.warn(wrapError(e, 'Generating sourceMapURL failed.'));
134+
}
135+
}
136+
129137
if (typeof options.sourceMap === 'boolean' && options.sourceMap) {
130138
options.sourceMap = {
131139
sourceMapBasepath: options.sourceMapBasepath,

test/less_test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ exports.less = {
135135
test.ok(actual.indexOf('/*# sourceMappingURL=custom/url/for/sourceMap.css.map') !== -1, 'compiled file should have a custom source map URL.');
136136
test.done();
137137
},
138+
sourceMapURLFunction: function(test) {
139+
test.expect(1);
140+
141+
var actual = read('tmp/sourceMapURLFunction.css');
142+
test.ok(actual.indexOf('/*# sourceMappingURL=../maps/sourceMapURLFunction.css.map') !== -1, 'compiled file should have a dynamic source map URL.');
143+
test.done();
144+
},
138145
sourceMapBasepath: function(test) {
139146
test.expect(1);
140147

0 commit comments

Comments
 (0)