1

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

例子:

少文件:

p {
    font-size: 14px;
}



a {
    color: red;
}

使用 Codekit 编译的 CSS 文件:

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

1 回答 1

1

使用默认命令行或客户端时,您可以轻松添加自 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;
}
于 2014-10-24T00:18:10.727 回答