From 133969589793238b60136dcac027e4eb0aba70e6 Mon Sep 17 00:00:00 2001 From: Bass Jobsen Date: Sat, 24 Jan 2015 14:46:06 +0100 Subject: [PATCH] suggestion to no use the sourceMapFileInline option When searching for a solution for https://github.com/plus3network/gulp-less/issues/126 i wondered why using Less with sourceMapFileInline (setting the SourceContent property of the source map with source files contents). Not using the sourceMapFileInline and using `result.map` directly gives me the same results after some testing. --- index.js | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index 04a98ae..f99c119 100644 --- a/index.js +++ b/index.js @@ -33,35 +33,24 @@ module.exports = function (options) { opts.filename = file.path; // Bootstrap source maps. + if (file.sourceMap) { - opts.sourceMap = { - sourceMapFileInline: true - }; + opts.sourceMap = {}; } - + less.render(str, opts) .then(function(result, opts){ var css = result.css; - - file.contents = new Buffer(css); - + file.contents = new Buffer(convert.removeComments(css)); file.path = gutil.replaceExtension(file.path, '.css'); - - if (file.sourceMap) { - var comment = convert.fromSource(css); - if (comment) { - file.contents = new Buffer(convert.removeComments(css)); - var sourceMap = comment.sourcemap; - for (var i = 0; i < sourceMap.sources.length; i++) { - sourceMap.sources[i] = path.relative(file.base, sourceMap.sources[i]); - } - sourceMap.file = file.relative; - applySourceMap(file, sourceMap); - } + result.map = JSON.parse(result.map); + result.map.file = file.relative; + for (var i = 0; i < result.map.sources.length; i++) { + if(typeof result.map.sources[i] !== "undefined") result.map.sources[i] = path.relative(file.base, result.map.sources[i]); } - - cb(null, file); - }, function(err){ + applySourceMap(file, result.map); + cb(null, file); + }, function(err){ // Convert the keys so PluginError can read them err.lineNumber = err.line; err.fileName = err.filename;