原文来自://www.greatytc.com/p/5a35a67eefd7
功能描述
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)
});