gulp.基础
1.安装
全局安装
npm install --global gulp
作为项目的开发依赖安装
npm install gulp --save-dev
2.在根目录下创建一个名为gulpfile.js的文件
let gulp = require('gulp'); let cleanCSS = require('gulp-clean-css');//css 打包 let concat = require('gulp-concat');//文件整合 let uglify = require('gulp-uglify');//js压缩插件 let zip = require('gulp-zip');//zip压缩文件 let less = require('gulp-less');//less压缩 gulp.task('minify-css', () => { return gulp.src('css/imdex.css') .pipe(concat('imdex.min.css')) .pipe(cleanCSS()) .pipe(gulp.dest('./css')); }); gulp.task('uglify-js',()=>{ return gulp.src('./js/*.js') .pipe(uglify()) .pipe(concat) .pipe(gulp.dest('./js')) }) gulp.task('zip-suo',()=>{ return gulp.src('./src/*') .pipe(zip()) .pipe(gulp.dest('./')) }) gulp.task('testLess', function () { gulp.src('src/less/index.less') //该任务针对的文件 .pipe(less()) //该任务调用的模块 .pipe(cleanCSS()) .pipe(gulp.dest('src/css')); //将会在src/css下生成index.css }); gulp.task('default',['minify-css','uglify-js','testLess']);