2014-09-27 113 views
3

有没有办法在LESS中创建无声多行注释?我需要与/ /注释相同的行为,但对于多行字符串。LESS无声多行注释

+1

您是否尝试使用'-x'选项或'clean-css'来压缩/缩小? – Harry 2014-09-27 10:55:07

+0

我很想知道是否还有一个无声的多行评论 – 2016-09-25 04:04:14

回答

2

正如@harry所示,-xclean-css选项也可以删除评论。从版本2开始,clean-css选项已被移入插件(npm install -g less-plugin-clean-css)。

由于少了2个,你可以使用插件,另见http://lesscss.org/usage/#plugins,这样你就可以编写和使用一个插件来删除你的多行注释。

例子:

下载并解压清理CSS到你的工作目录。您可以在https://github.com/jakubpawlowicz/clean-css找到干净的CSS(这将创建一个子旧的所谓清洗CSS-主)

不是创建你的插件,调用这个文件less-plugin-remove-comments.js

var getCommentsProcessor = require("./comments-processor"); 

module.exports = { 
    install: function(less, pluginManager) { 
     var CommentsProcessor = getCommentsProcessor(less); 
     pluginManager.addPostProcessor(new CommentsProcessor()); 
    } 
}; 

comment-processor.js比可能包括以下:

var cleaner = require('./clean-css-master/lib/text/comments-processor'); 

module.exports = function(less) { 
    function CommentProcessor(options) { 
     this.options = options || {}; 
    }; 

    CommentProcessor.prototype = { 
     process: function (css) { 
      var commentsProcessor = new cleaner('*', false); 
      css = commentsProcessor.escape(css); 
      return css; 
     } 
    }; 

    return CommentProcessor; 
}; 

最后,你应该能够运行以下命令:

lessc --plugin=./less-plugin-remove-comments.js index.less 

上述命令应该为您提供没有注释的编译CSS。