-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #798 from adaptlearning/less/ABU-680
Added custom less compiler and sourcemapper
- Loading branch information
Showing
9 changed files
with
116 additions
and
35 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,46 @@ | ||
module.exports = { | ||
options:{ | ||
compress:true | ||
}, | ||
dist: { | ||
files: { | ||
'<%= outputdir %>adapt/css/adapt.css' : '<%= sourcedir %>less/adapt.less' | ||
module.exports = function (grunt, options) { | ||
return { | ||
dev: { | ||
options:{ | ||
mandatory: [ | ||
'<%= sourcedir %>core/less/*.less' | ||
], | ||
src: [ | ||
'<%= sourcedir %>menu/<%= menu %>/**/*.less', | ||
'<%= sourcedir %>components/**/*.less', | ||
'<%= sourcedir %>extensions/**/*.less', | ||
'<%= sourcedir %>theme/<%= theme %>/**/*.less' | ||
], | ||
sourcemaps:true, | ||
compress:false, | ||
dest: '<%= outputdir %>adapt/css/', | ||
cssFilename: "adapt.css", | ||
mapFilename: "adapt.css.map", | ||
filter: function(filepath) { | ||
return grunt.config('helpers').includedFilter(filepath); | ||
} | ||
} | ||
}, | ||
compile: { | ||
options: { | ||
mandatory: [ | ||
'<%= sourcedir %>core/less/*.less' | ||
], | ||
src: [ | ||
'<%= sourcedir %>menu/<%= menu %>/**/*.less', | ||
'<%= sourcedir %>components/**/*.less', | ||
'<%= sourcedir %>extensions/**/*.less', | ||
'<%= sourcedir %>theme/<%= theme %>/**/*.less' | ||
], | ||
sourcemaps: false, | ||
compress:true, | ||
dest: '<%= outputdir %>adapt/css/', | ||
cssFilename: "adapt.css", | ||
mapFilename: "adapt.css.map", | ||
filter: function(filepath) { | ||
return grunt.config('helpers').includedFilter(filepath); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
module.exports = function(grunt) { | ||
grunt.registerMultiTask('less', 'Compile LESS files to CSS', function() { | ||
var less = require('less'); | ||
var _ = require('underscore'); | ||
var path = require("path"); | ||
var done = this.async(); | ||
var options = this.options({}); | ||
|
||
var imports = ""; | ||
|
||
if (options.mandatory) { | ||
for (var i = 0, l = options.mandatory.length; i < l; i++) { | ||
var src = options.mandatory[i]; | ||
grunt.file.expand({}, src).forEach(function(path) { | ||
imports+= "@import '" + path + "';\n"; | ||
}); | ||
} | ||
} | ||
|
||
if (options.src) { | ||
for (var i = 0, l = options.src.length; i < l; i++) { | ||
var src = options.src[i]; | ||
grunt.file.expand({filter: options.filter}, src).forEach(function(path) { | ||
imports+= "@import '" + path + "';\n"; | ||
}); | ||
} | ||
} | ||
|
||
var sourcemaps; | ||
if (options.sourcemaps) { | ||
sourcemaps = { | ||
"sourceMap": { | ||
"sourceMapFileInline": false, | ||
"outputSourceFiles": true, | ||
"sourceMapBasepath": "src", | ||
"sourceMapURL": options.mapFilename, | ||
} | ||
}; | ||
} else { | ||
var sourceMapPath = path.join(options.dest, options.mapFilename); | ||
if (grunt.file.exists(sourceMapPath)) grunt.file.delete(sourceMapPath, {force:true}); | ||
if (grunt.file.exists(sourceMapPath+".imports")) grunt.file.delete(sourceMapPath+".imports", {force:true}); | ||
} | ||
|
||
var lessOptions = _.extend({ "compress": options.compress }, sourcemaps); | ||
|
||
less.render(imports, lessOptions, complete); | ||
|
||
function complete(error, output) { | ||
if (error) { | ||
grunt.fail.fatal(JSON.stringify(error, false, " ")); | ||
return; | ||
} | ||
|
||
grunt.file.write(path.join(options.dest, options.cssFilename), output.css); | ||
|
||
if (output.map) { | ||
grunt.file.write(path.join(options.dest, options.mapFilename)+".imports", imports); | ||
grunt.file.write(path.join(options.dest, options.mapFilename), output.map); | ||
} | ||
done(); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters