Answer the question
In order to leave comments, you need to log in
How to properly configure grunt-contrib-cssmin?
Hello, there is grunt'a config. (I'm doing it for the first time, don't kick much, what to fix, say, thanks)
They glue the css files, then I minify them. And then the problem crashes, if there are comments in the css file (for example, in animate.css), then after minification the css is all commented out. What am I doing wrong? How is it treated?
Gruntfile.js
module.exports = function (grunt) {
grunt.initConfig({
clean: {
folder: ['build/']
},
bower: {
dev: {
dest: 'public/',
js_dest: 'public/js/lib',
css_dest: 'public/css/lib',
fonts_dest: 'public/fonts/',
images_dest: 'public/img/'
}
},
concat: {
js: {
src: ['public/js/**'],
dest: 'public/js/chill.js'
},
css: {
src: ['public/css/**'],
dest: 'public/css/chill.css'
}
},
autoprefixer: {
options: {
browsers: ['last 2 versions', 'ie 8', 'ie 9', '> 1%']
},
main: {
expand: true,
flatten: true,
src: 'public/css/chill.css',
dest: 'public/css/'
}
},
uglify: {
dist: {
src: ['<%= concat.js.dest %>'],
dest: 'build/js/chill.min.js'
}
},
cssmin: {
dist: {
src: ['<%= concat.css.dest %>'],
dest: 'build/css/chill.min.css'
}
},
imagemin: {
dynamic: {
files: [{
expand: true,
cwd: 'public/img',
src: ['*'],
dest: 'build/img',
}]
}
},
copy: {
main: {
expand: true,
cwd: 'public/',
src: ['fonts/*'],
dest: 'build/'
}
},
clean: {
css: ['<%= concat.css.dest %>'],
js: ['<%= concat.js.dest %>']
}
});
grunt.loadNpmTasks('grunt-bower');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.registerTask('default', ['bower', 'concat', 'uglify', 'autoprefixer', 'uglify', 'cssmin', 'imagemin', 'copy', 'clean']);
};
Answer the question
In order to leave comments, you need to log in
Found a solution.
You need to run cssmin with the keepSpecialComments: 0 parameter.
Then all comments are simply deleted, which is actually correct when building the release version.
Everything seems to be correct in the config. Either write a CSS comment in such a clever way that the parser stumbles in cssmin or autoprefixer, or a bug in one of these processors (which is unlikely).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question