Reputation: 271
I am using gulp-clean-css with my gulp build system, but clean-css is not minifying the files. If I change the destination directory to anything else, it works and minifies the files correctly. The destination directory "build/css/".
Here is my code:
gulp.src ("css/*.css")
.pipe (cleancss ({ level: 2 }))
.pipe (gulp.dest ("build/css"));
Working code but in wrong directory:
gulp.src ("css/*.css")
.pipe (cleancss ({ level: 2 }))
.pipe (gulp.dest ("build/csss"));
In the command line version of cleancss:
cleancss css/game.css -o build/css/game.css
It works fine with no problems.
Upvotes: 0
Views: 1644
Reputation: 271
So I figured out the problem. In another task I was using, I told csslint to pipe to gulp.dest ("build/css")
when I shouldn't have. Then cleancss was trying to overwrite that file but was unable to.
Simply removing the line where csslint was piping to build/css
fixed the whole problem.
Upvotes: 1
Reputation: 77
It seems like the reason is that cleancss trying to rewrite existing (original) CSS file. Perhaps, original CSS file are blocked for changes and actually defends you from deleting your original *.css files.
So you have 2 options:
If its important for you to save cleaned files in the original folder rename the cleaned files. Also its recommended to concatenate all CSS files before you clean them. It will allow you to save some additional time on page load.
gulp.src("css/*.css")
.pipe(cleancss ({ level: 2 }))
.pipe(concat('styles.css'))
.pipe(rename('styles.min.css'))
.pipe(gulp.dest ("build/csss"));
Dont forget to install required modules.
var concat = require('gulp-concat');
var rename = require('gulp-rename');
Upvotes: 2