Skip to content

Using clean-css directly in your gulp recipe #342

@sogko

Description

@sogko

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy