2014-09-27 112 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。