From 176260a035f4d6e5d82cceedebe24bcd83fac6a1 Mon Sep 17 00:00:00 2001 From: Luke Page Date: Sat, 14 Sep 2013 19:33:08 +0100 Subject: [PATCH] allow sourcemaps to be inline, in the css --- bin/lessc | 12 +++++++----- lib/less/source-map-output.js | 19 +++++++++++++++---- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/bin/lessc b/bin/lessc index 499df63b..487283bc 100755 --- a/bin/lessc +++ b/bin/lessc @@ -247,11 +247,13 @@ if (options.depends) { sys.print(outputbase + ": "); } -var writeSourceMap = function(output) { - var filename = options.sourceMapFullFilename || options.sourceMap; - ensureDirectory(filename); - fs.writeFileSync(filename, output, 'utf8'); -}; +if (options.sourceMap !== "inline") { + var writeSourceMap = function(output) { + var filename = options.sourceMapFullFilename || options.sourceMap; + ensureDirectory(filename); + fs.writeFileSync(filename, output, 'utf8'); + }; +} var parseLessFile = function (e, data) { if (e) { diff --git a/lib/less/source-map-output.js b/lib/less/source-map-output.js index 821cfc9f..8ecf9ffa 100644 --- a/lib/less/source-map-output.js +++ b/lib/less/source-map-output.js @@ -1,5 +1,4 @@ (function (tree) { - var sourceMap = require("source-map"); tree.sourceMapOutput = function (options) { this._css = []; @@ -11,6 +10,7 @@ this._sourceMapBasepath = options.sourceMapBasepath; this._sourceMapRootpath = options.sourceMapRootpath; this._outputSourceFiles = options.outputSourceFiles; + this._sourceMapGeneratorConstructor = options.sourceMapGenerator || require("source-map").SourceMapGenerator; if (this._sourceMapRootpath && this._sourceMapRootpath.charAt(this._sourceMapRootpath.length-1) !== '/') { this._sourceMapRootpath += '/'; @@ -66,7 +66,7 @@ }; tree.sourceMapOutput.prototype.toCSS = function(env) { - this._sourceMapGenerator = new sourceMap.SourceMapGenerator({ file: this._outputFilename, sourceRoot: null }); + this._sourceMapGenerator = new this._sourceMapGeneratorConstructor({ file: this._outputFilename, sourceRoot: null }); if (this._outputSourceFiles) { for(var filename in this._contentsMap) { @@ -77,10 +77,21 @@ this._rootNode.genCSS(env, this); if (this._css.length > 0) { - this._writeSourceMap(JSON.stringify(this._sourceMapGenerator.toJSON())); + var sourceMapFilename, + sourceMapContent = JSON.stringify(this._sourceMapGenerator.toJSON()); if (this._sourceMapFilename) { - this._css.push("/*# sourceMappingURL=" + this.normalizeFilename(this._sourceMapFilename) + " */"); + sourceMapFilename = this.normalizeFilename(this._sourceMapFilename); + } + + if (this._writeSourceMap) { + this._writeSourceMap(sourceMapContent); + } else { + sourceMapFilename = "data:application/json," + encodeURIComponent(sourceMapContent); + } + + if (sourceMapFilename) { + this._css.push("/*# sourceMappingURL=" + sourceMapFilename + " */"); } }