gulp插件(1) - gulp-uglify(压缩JS文件)
2017-10-25 本文已影响7人
学好该死的程序
功能描述
gulp-uglify插件用于JS文件压缩
安装命令
$ cnpm install gulp-uglify --save-dev
使用方法
例1:基本使用
var gulp = require('gulp'),
uglify = require('gulp-uglify'),
pump = require('pump');
gulp.task('jsmin', function(cb) {
pump([
gulp.src('src/js/index.js'),
uglify(),
gulp.dest('dist/js')
], cb)
});
例2:压缩多个JS文件,输出至指定目录
var gulp = require('gulp'),
uglify = require('gulp-uglify'),
pump = require('pump');
gulp.task('jsmin', function(cb) {
pump([
gulp.src(['src/js/demo1.js', 'src/js/demo2.js']),
uglify(),
gulp.dest('dist/js')
], cb)
});
例3:使用通配符“!”,“”,“*”,“{}”进行模式匹配
var gulp = require('gulp'),
uglify = require('gulp-uglify'),
pump = require('pump');
gulp.task('jsmin', function(cb) {
pump([
gulp.src(['src/js/*.js']),
uglify(),
gulp.dest('dist/js')
], cb)
});