Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using clean-css directly in your gulp recipe #342

Closed
sogko opened this issue Aug 19, 2014 · 2 comments
Closed

Using clean-css directly in your gulp recipe #342

sogko opened this issue Aug 19, 2014 · 2 comments

Comments

@sogko
Copy link

sogko commented Aug 19, 2014

Hi guys,

I just want to share a gulp recipe to minify css using the CleanCSS library, with the help of vinyl-map (a really useful library by @hughsk that you can use adapt most nodejs modules to work into your gulp streams)

var gulp = require('gulp');
var CleanCSS = require('clean-css');
var map = require('vinyl-map');

gulp.task('minify-css' , function minifyCSSTask() {
  // this snippet basically replaces `gulp-minify-css`
  var minify = map(function (buff, filename) {
    return new CleanCSS({
      // specify your clean-css options here
    }).minify(buff.toString());
  });

  return gulp.src('css/**/*.css')
    .pipe(minify)
    .pipe(gulp.dest('dist'));
});

This helps to reduce the need for a gulp-plugin wrapping around clean-css and allows you to use clean-css outside of your gulpfile.js

@jakubpawlowicz
Copy link
Collaborator

I've just added it to our Readme. Thanks for the useful tip!

@philippe-git
Copy link

Updated recipe for clean-css 3.x:

var gulp = require('gulp');
var CleanCSS = require('clean-css');
var map = require('vinyl-map');

gulp.task('minify-css' , function minifyCSSTask() {
  // this snippet basically replaces `gulp-minify-css`
  var minify = map(function (buff, filename) {
    return new CleanCSS({
      // specify your clean-css options here
    }).minify(buff.toString()).styles;
  });

  return gulp.src('css/**/*.css')
    .pipe(minify)
    .pipe(gulp.dest('dist'));
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants