使用默认命令行或客户端时,您可以轻松添加自 v2 以来的自己的插件。Less 保留/**/
评论。
添加您的 LESS 代码,例如/*3*/
3 个换行符。
现在编写插件,调用这个文件less-plugin-add-newlines.js
:
var getCommentsProcessor = require("./comments-processor");
module.exports = {
install: function(less, pluginManager) {
var CommentsProcessor = getCommentsProcessor(less);
pluginManager.addPostProcessor(new CommentsProcessor());
}
};
比写comments-processor.js
:
String.prototype.repeat = function( num )
{
return new Array( num + 1 ).join( this );
}
module.exports = function(less) {
function CommentProcessor(options) {
this.options = options || {};
};
CommentProcessor.prototype = {
process: function (css) {
var r = new RegExp("(\\/\\*)([0-9]+)(\\*\\/)","g");
return css.replace(r,function(m1,m2,m3){ return "\n".repeat(m3*1-1); });
}
};
return CommentProcessor;
};
较少的
p1 {
p:3;
}
/*3*/
p2 {
p:3;
}
/*4*/
p2 {
p:3;
}
运行时会编译成前面的lessc --plugin=less-plugin-add-newlines.js index.less
:
p1 {
p: 3;
}
p2 {
p: 3;
}
p2 {
p: 3;
}