Home  >  Article  >  Web Front-end  >  Detailed explanation of Grunt compressed images and JS examples

Detailed explanation of Grunt compressed images and JS examples

零下一度
零下一度Original
2017-06-26 10:04:361491browse

Today we will talk about using Grunt to compress images and JS!

First you need to install the plug-in:

This is for compressing images;

npm install --save-dev gulp-imagemin

This is to compress JS:

npm install --save-dev gulp-imagemin

Then introduce dependencies:

var gulp = require("gulp");

Introducing the plug-in:

  var imagemin = require('gulp-imagemin');//压缩图片
  var uglifyJS = require('gulp-uglify');//压缩JS

//然后 配置任务

gulp.task('uglifyJS',function(){
 gulp.src('js/sum.js')
 .pipe(uglifyJS( ))
.pipe(gulp.dest('dest'));
});

gulp.task('imagemin',function(){
gulp.src(' img/*.{jpg,png,gif}')
 .pipe(imagemin())
 .pipe(gulp.dest("dest"));
})

//The default registration setting is

gulp.task('default',['uglifyJS','imagemin']);

This is what it looks like after running through !

That’s it! Do you understand?

The above is the detailed content of Detailed explanation of Grunt compressed images and JS examples. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn