我正在尝试使用Grunt和grunt-contrib-cssmin删除所有的CSS注释,CSS文件被编译并缩小了所有注释。
注释应与行: keepSpecialComments: 0一起删除
module.exports = function(grunt) {
require('jit-grunt')(grunt);
grunt.initConfig({
less: {
development: {
options: {
compress: true,
yuicompress: true,
optimization: 2
},
files: {
"css/main.css": "less/bootstrap.less" // destination file and source file
}
}
},
watch: {
styles: {
files: ['less/**/*.less'], // which files to watch
tasks: ['less'],
options: {
nospawn: true
}
},
},
cssmin: {
options: {
keepSpecialComments: 0
}
}
});
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.registerTask('default', ['less','cssmin', 'watch']);
};发布于 2016-01-05 21:13:41
根据作者提供的答案类型,grunt-decomment将是一个更通用的解决方案,它可以从任何文件中删除像//和/**/这样的注释。
发布于 2015-10-08 18:31:01
修复-我找到了一个使用grunt strip css- comments的解决方案,它会在文件缩小后删除所有注释:
下面更正的代码:
module.exports = function(grunt) {
require('jit-grunt')(grunt);
require('load-grunt-tasks')(grunt);
grunt.initConfig({
less: {
development: {
options: {
compress: true,
yuicompress: true,
optimization: 2
},
files: {
"public/library/css/bootstrap.min.css": "public/library/less/bootstrap.less"
}
}
},
watch: {
styles: {
files: ['public/library/less/**/*.less'],
tasks: ['less', 'stripCssComments'],
options: {
nospawn: true,
livereload: 1342
}
},
},
stripCssComments: {
dist: {
files: {
'public/library/css/bootstrap.min.css': 'public/library/css/bootstrap.min.css'
},
options: {
preserve: false
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['less', 'stripCssComments', 'watch']);
};https://stackoverflow.com/questions/32994523
复制相似问题