Gulp 从0开始

http://www.w3ctech.com/topic/134  (该文章有很多错误)
http://segmentfault.com/a/1190000000372547
http://www.cnblogs.com/chyingp/p/gulp-introduction.html 
 
 
先node init 生成package文件
 
$ npm install -g gulp  安装gulp命令行工具  OR  npm install -g gulp --registry=http://registry.npm.taobao.org
$ npm install gulp --save-dev 在项目中安装gulp
 
Gulp配置文件名必须是 gulpfile.js 使用的是gulp 'taskname'命令  (不是node啦!) 
 
第一个Gulp
先试试最常用的jshint  https://www.npmjs.com/package/gulp-jshint  (官方文档很详细)
 
基本照着官方文档来的  但是官方文档还是有点问题....
 
var gulp = require('gulp'),
    jshint = require('gulp-jshint'),
    concat = require('gulp-concat'),
    rename = require('gulp-rename'),
    uglify = require('gulp-uglify');
var map = require('map-stream');


gulp.task('minify', function () {
   gulp.src('../resources/module/quality_data/js/*.js')
      .pipe(concat('concat.js'))
      .pipe(gulp.dest('build')) // 拼起来后输出到build文件夹
      .pipe(rename({suffix: '.min'}))   //rename压缩后的文件名
      .pipe(uglify())
      .pipe(gulp.dest('build'))
});

var myReporter = map(function (file, cb) {
  if (!file.jshint.success) {
    console.log('JSHINT fail in '+file.path);
    file.jshint.results.forEach(function (err) {
      if (err) {
        // console.log(err);
        console.log(' '+file.path + ': line ' + err.error.line + ', col ' + err.error.character + ', code ' + err.error.code + ', ' + err.error.reason);
      }
    });
  }
  cb(null, file);
});

gulp.task('lint', function() {
  return gulp.src('../resources/module/**/*.js')  // **的意思是所有文件夹及里面的子文件夹  *s是子目录 不递归
    .pipe(jshint())
    // .pipe(myReporter); //reporter 是一个自定义的报告
    .pipe(jshint.reporter('default', { verbose: true }));
});
 
原文地址:https://www.cnblogs.com/cart55free99/p/4411671.html