gulp

Posted 骑士007

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了gulp相关的知识,希望对你有一定的参考价值。

参考文档:https://gulpjs.com/
     https://markpop.github.io/2014/09/17/Gulp%E5%85%A5%E9%97%A8%E6%95%99%E7%A8%8B/
     http://www.gulpjs.com.cn/docs/api/
     http://www.cnblogs.com/hutuzhu/p/5276000.html



1
var gulp = require(\'gulp\'); 2 var clean = require(\'gulp-clean\'); 3 var sass = require(\'gulp-sass\'); 4 var runSequence = require(\'run-sequence\'); 5 var autoprefixer = require(\'gulp-autoprefixer\'); 6 var concat = require(\'gulp-concat\'); 7 var uglify = require(\'gulp-uglify\'); 8 var pump = require(\'pump\') 9 10 11 var src = { 12 sass: [ 13 \'src/sass/**/*.sass\' //编译用 14 ], 15 css: [ 16 \'src/css/**/*.css\' //清除用 17 ] 18 }; 19 20 var build = { 21 css: \'src/css\', 22 }; 23 24 25 function log(msg) { 26 util.log(util.colors.blue(msg)); 27 } 28 29 // 处理错误 30 function handleError(err) { 31 log(err.toString()); 32 this.emit(\'end\'); 33 } 34 35 //--------------------------------------- 36 gulp.task(\'清除\', function () { 37 return gulp.src(src.css, { 38 read: false 39 }) 40 .pipe(clean({ 41 force: true 42 })); 43 }); 44 45 46 gulp.task(\'监听\', function () { 47 runSequence(\'清除\', [\'编译\']); 48 // gulp.watch(src.css, [\'监听\']); 49 }); 50 51 52 //--------------------------------------- 53 54 55 gulp.task(\'编译\', function () { 56 return gulp.src(src.sass) 57 .pipe(sass().on(\'error\', sass.logError)) 58 .pipe(autoprefixer({ 59 browsers: [\'ios >= 7\', \'android >= 4.1\'] 60 })) 61 .pipe(gulp.dest(build.css)) 62 }); 63 64 gulp.task(\'watch\', function () { 65 gulp.watch(src.sass, [\'监听\']); 66 67 }); 68 69 //++++++++++++++++++++++++++++ 70 71 gulp.task(\'scripts\', function () { 72 return gulp.src([\'./src/nJs/one.js\', \'./src/nJs/two.js\']) 73 .pipe(concat({path: \'new.js\', stat: {mode: 0666}})) 74 .pipe(gulp.dest(\'./src/outJs\')); 75 }); 76 77 78 gulp.task(\'watch:script\', function () { 79 gulp.watch(\'./src/nJs/**/*.js\', [\'scripts\']); 80 81 }); 82 83 84 //----------------------压缩代码--------------------------- 85 86 gulp.task(\'compress\', function (cb) { 87 pump([ 88 gulp.src(\'./src/nJs/**/*.js\'), 89 uglify(), 90 gulp.dest(\'./dist\') 91 ], 92 cb 93 ); 94 }); 95 96 //------------------------------------------------ 97 98 gulp.task(\'build-1\', function () { 99 runSequence(\'清除\', [\'编译\']); 100 // gulp.start(\'build:app\', \'build:vendor\'); 101 }); 102 103 gulp.task(\'default\', function () { 104 runSequence(\'build-1\',\'scripts\',"compress", [\'watch\',\'watch:script\']); 105 });

 

以上是关于gulp的主要内容,如果未能解决你的问题,请参考以下文章

gulp 项目构建 代码压缩与混淆

使用gulp进行代码压缩

gulp

gulp压缩构建代码

在 vs 代码中打开项目时未检测到 Gulp 任务

Gulp/Typescript/Async/Await 代码不起作用 - 为啥?