CodeKit 2-使用代码中的空行编译较少的代码



我正在使用Codekit 2.1.8编译LESS文件。在我的LESS文件中,我有空行,我也想把它们放在编译的CSS文件中,但Codekit似乎要删除它们。我在Codekit中找不到任何与此问题相关的选项。

示例:

LESS文件:

p {
    font-size: 14px;
}

a {
    color: red;
}

与Codekit兼容的CSS文件:

p {
    font-size: 14px;
}
a {
    color: red;
}

使用默认命令行或客户端时,您可以很容易地添加自v2以来的插件。较少保留/**/注释。

添加您的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;
}

最新更新