[英]CodeKit 2 - compiling less with empty lines in code
I'm using Codekit 2.1.8 to compile my LESS files. 我正在使用Codekit 2.1.8编译我的LESS文件。 In my LESS files I have empty lines and I want to have them in compilied CSS file too, but Codekit seems to delete them.
在我的LESS文件中,我有空行,我也希望将它们包含在已编译的CSS文件中,但是Codekit似乎删除了它们。 I can't find any options in Codekit related to this issue.
我在Codekit中找不到与此问题相关的任何选项。
Example: 例:
LESS file: LESS文件:
p {
font-size: 14px;
}
a {
color: red;
}
Compilied CSS file with Codekit: 使用Codekit编译的CSS文件:
p {
font-size: 14px;
}
a {
color: red;
}
When using the default command line or client side you can easily add your own plugins since v2. 从v2开始,使用默认命令行或客户端时,您可以轻松添加自己的插件。 Less preserves
/**/
comments. 较少保留
/**/
注释。
Add in your LESS code for instance /*3*/
for 3 newlines. 在您的LESS代码中添加例如
/*3*/
的3个换行符。
Now write the plugin, call this file less-plugin-add-newlines.js
: 现在编写插件,将其命名为
less-plugin-add-newlines.js
:
var getCommentsProcessor = require("./comments-processor");
module.exports = {
install: function(less, pluginManager) {
var CommentsProcessor = getCommentsProcessor(less);
pluginManager.addPostProcessor(new CommentsProcessor());
}
};
Than write the comments-processor.js
: 比写
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;
};
less 减
p1 {
p:3;
}
/*3*/
p2 {
p:3;
}
/*4*/
p2 {
p:3;
}
The preceding will compile into when running lessc --plugin=less-plugin-add-newlines.js index.less
: 在运行
lessc --plugin=less-plugin-add-newlines.js index.less
时, lessc --plugin=less-plugin-add-newlines.js index.less
将编译为:
p1 {
p: 3;
}
p2 {
p: 3;
}
p2 {
p: 3;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.