And*_*nov 5 comments multiline less
有没有办法在 LESS 中创建无声的多行注释?我想要与 //comment 相同的行为,但对于多行字符串。
正如 @harry 已经明确指出的,-x
和clean-css
选项也删除了评论。从版本 2 开始,clean-css 选项已移至插件 ( npm install -g less-plugin-clean-css
) 中。
从 Less 2 开始,您可以使用插件,另请参阅http://lesscss.org/usage/#plugins,这样您就可以编写和使用一个插件来删除多行注释。
例子:
下载 clean-css 并将其解压到您的工作目录中。您可以在https://github.com/jakubpawlowicz/clean-css找到 clean-css (这将创建一个名为 clean-css-master 的旧子版本)
创建插件后,调用此文件less-plugin-remove-comments.js
:
var getCommentsProcessor = require("./comments-processor");
module.exports = {
install: function(less, pluginManager) {
var CommentsProcessor = getCommentsProcessor(less);
pluginManager.addPostProcessor(new CommentsProcessor());
}
};
Run Code Online (Sandbox Code Playgroud)
您的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;
};
Run Code Online (Sandbox Code Playgroud)
最后您应该能够运行以下命令:
lessc --plugin=./less-plugin-remove-comments.js index.less
Run Code Online (Sandbox Code Playgroud)
前面的命令应该为您提供编译后的 CSS,不带注释。
归档时间: |
|
查看次数: |
640 次 |
最近记录: |