var gulp=require('gulp');
var plumber = require('gulp-plumber');//让错误恢复过来
var sourcemaps = require('gulp-sourcemaps');
//压缩js
/*================文件连接======================================*/
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var notify = require('gulp-notify');




gulp.task('jsConcat', function() {
	  return gulp.src([
					   'js/lib/help.js',
					   'js/models/models.js',
					   'js/collections/realtime.js', 
					   'js/templates/templates.js',
					   'js/views/views.js',
					   'js/route/route.js',
					   'js/app.js'
					   ])
    .pipe(concat('all.js'))
    .pipe(gulp.dest('js/dist/'))
});


gulp.task('jsMin', function() {
    return gulp.src('js/dist/*.js',{
        // mangle:true,//开启混淆功能,
        mangle: {except: ['require' ,'exports' ,'module' ,'$','Backbone']},
        output:{
            beautify:false,
            indent_level:4
        },
        compress:true,
        preserveComments:false
    })
        .pipe(plumber())
        .pipe(sourcemaps.write())
        .pipe(sourcemaps.write('maps',{
            includeContent:false
        }))
        .pipe(uglify())
        .pipe(gulp.dest('js/dist/min'));
});


gulp.task('test:watch',['jsConcat','jsMin'], function () {
    gulp.watch(['js/*/*.js','js/*.js'],['jsConcat','jsMin']);
});





