1、安装gulp-uglify
命令行输入npm install gulp-uglify --save-dev ;
2、配置文件
2.1基本使用
var gulp = require(‘gulp‘), uglify = require(‘gulp-uglify‘); //获取uglify插件 gulp.task(‘jsmin‘, function () { gulp.src(‘src/js/index.js‘) //引入js文件 .pipe(uglify()) .pipe(gulp.dest(‘dist/js‘)); });
2.2压缩多个JS文件
var gulp = require(‘gulp‘), uglify = require(‘gulp-uglify‘); gulp.task(‘jsmin‘, function () { gulp.src([‘src/js/index.js‘,‘src/js/detail.js‘]) //多个文件以数组形式传入 .pipe(uglify()) .pipe(gulp.dest(‘dist/js‘)); });
3、执行任务
命令行输入:gulp jsmin
时间: 2024-11-11 22:48:42