shkuznetsov / gulp-minify-inline

gulp plugin that minifies inline JS and CSS
MIT License
28 stars 5 forks source link

gulp-minify-inline NPM version Build Status

gulp-minify-inline is a gulp plugin that minifies inline JS and CSS. Works best with gulp-minify-html.

Uses cheerio to parse HTML, terser to minify JS and clean-css to minify CSS.

Installation

Install package with NPM and add it to your development dependencies:

npm install --save-dev gulp-minify-inline

Usage

Straightforward way:

var minifyInline = require('gulp-minify-inline');

gulp.task('minify-inline', function() {
  gulp.src('src/*.html')
    .pipe(minifyInline())
    .pipe(gulp.dest('dist/'))
});

Need a bit more control?

var minifyInline = require('gulp-minify-inline');

var options = {
  js: {
    output: {
      comments: true
    }
  },
  jsSelector: 'script[type!="text/x-handlebars-template"]',
  css: {
    level: {1: {specialComments: 0}}
  },
  cssSelector: 'style[data-do-not-minify!="true"]'
};

gulp.task('minify-inline', function() {
  gulp.src('src/*.html')
    .pipe(minifyInline(options))
    .pipe(gulp.dest('dist/'))
});

Options

Right now the following options are supported:

LICENSE

MIT License