allow sourcemaps to be inline, in the css

This commit is contained in:
Luke Page
2013-09-14 19:33:08 +01:00
parent ebc6f5e1df
commit 176260a035
2 changed files with 22 additions and 9 deletions

View File

@@ -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) {

View File

@@ -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 + " */");
}
}