gulpfile.js 文件项目

打包文件项目

var gulp = require('gulp')
var $ = require('gulp-load-plugins')()
var replace = require('gulp-replace-task')
var es = require('event-stream')
var del = require('del')

var path = 'www/static/';
var assets = {
  less: [
    'src/vc800/pepm.min.less',
    'src/vc800/ie.min.less'
  ],
  rev: [
    'src/version.php'
  ]
};
var js = [
/*  {
    name: 'jquery',
    src: ['src/vc800/jquery-1.12.4.js']
  },
  {
    name: 'jsgrid',
    src: ['src/vc800/jsgrid.js']
  },*/
  {
    name: 'pepm',
    src: [
      // 'bower_components/jquery/dist/jquery.min.js',
      'bower_components/jquery.cookie/jquery.cookie.js',
      'bower_components/chosen/chosen.jquery.js',
      'bower_components/jquery-validation/dist/jquery.validate.js',
      'bower_components/jquery-validation/src/localization/messages_zh.js',
      'bower_components/ladda-bootstrap/dist/spin.js',
      'bower_components/ladda-bootstrap/dist/ladda.js',
      'src/vc800/bootstrap.js',
      // 'src/vc800/jquery-ui-datetimepicker-cn.js',
      'src/vc800/bootstrap-datetimepicker.js',
      'src/vc800/bootstrap-datetimepicker.zh-CN.js',
      'src/vc800/bootstrap.file-input.js',
      'src/vc800/bootbox.js',
      'src/vc800/pepm.js'
      ]
  },
  /*{
    name: 'simditor',
    src: [
      'bower_components/simple-module/lib/module.js',
      'bower_components/simple-hotkeys/lib/hotkeys.js',
      'bower_components/simple-uploader/lib/uploader.js',
      'bower_components/simditor/lib/simditor.js',
      'src/vc800/mobilecheck.js',
      ]
  },*/
  {
    name: 'entity',
    src: ['src/vc800/entity.js']
  },
  {
    name: 'workflow',
    src: ['src/vc800/workflow.js']
  },
  {
    name: 'board',
    src: [
      'bower_components/dragula.js/dist/dragula.js',
      'src/vc800/board.js'
    ]
  },
  {
    name: 'monitor',
    src: ['src/vc800/monitor.js']
  },
  {
    name: 'calendar',
    src: ['src/vc800/calendar.js']
  },
  {
    name: 'event',
    src: ['src/vc800/event.js']
  },
  {
    name: 'structure',
    src: ['src/vc800/structure.js']
  },
  {
    name: 'tagsinput',
    src: ['src/vc800/bootstrap-tagsinput.js']
  },
  {
    name: 'chained',
    src: ['src/vc800/chained.js']
  }
];

gulp.task('clean', function(cb) {
  return del(['**/.ds_store', '**/*.orig', 'app/cache/*', 'www/static/modules/**/*', 'www/static/layui/**/*'], cb);
});

gulp.task('js', ['rev'], function() {
  return es.merge(js.map(function (o) {
    return gulp.src(o.src)
      .pipe($.sourcemaps.init())
      .pipe($.cached(o.name))
      .pipe($.uglify())
      .pipe($.remember(o.name))
      .pipe($.concat(o.name + '.min.js'))
      .pipe($.sourcemaps.write('../'))
      .pipe(gulp.dest(path + 'js'))
      .pipe($.livereload());
  }));
});

gulp.task('plupload', function() {
  var plu_src = 'node_modules/plupload/js/',
    to = 'www/static/js/';
    // to = 'www/static/modules/';

  gulp.src([plu_src+'Moxie.swf', plu_src+'Moxie.xap'])
    .pipe(gulp.dest(to));
  gulp.src(plu_src+'i18n/zh_CN.js')
    .pipe($.rename('plupload.i18n.js'))
    .pipe(gulp.dest(to));

  return gulp.src(plu_src+'plupload.full.min.js')
    .pipe($.rename('plupload.js'))
    .pipe(gulp.dest(to));
})

gulp.task('layui_src', function() {
  return gulp.src('bower_components/layui/build/**')
    .pipe(gulp.dest('www/static/layui/'));
})

gulp.task('layui', function() {
  return gulp.src('src/layui/**/*.js')
    .pipe($.sourcemaps.init())
    .pipe($.uglify())
    .pipe($.sourcemaps.write('../'))
    .pipe(gulp.dest('www/static/modules/'))
    .pipe($.livereload());
})

gulp.task('less', ['rev'], function() {
  gulp.src(assets.less)
    .pipe($.sourcemaps.init())
    .pipe($.less())
    .pipe($.minifyCss({
      keepSpecialComments: false
    }))
    .pipe($.sourcemaps.write('../'))
    .pipe(gulp.dest(path + 'css'))
    .pipe($.livereload());
});

gulp.task('rev', function() {
  return gulp.src(assets.rev)
    .pipe(replace({
      patterns: [
        { match: 'ver', replacement: new Date().getTime() }
      ]
      }))
    .pipe(gulp.dest('app'));
});

gulp.task('watch', ['default'], function() {
  $.livereload.listen();
  gulp.watch(['src/vc800/**/*.css', 'src/vc800/**/*.less'], ['less']);
  js.map(function (o) {
    gulp.watch(o.src, ['js']);
  });
  gulp.watch('src/layui/**/*.js', ['layui']);
  gulp.watch('app/v/**/*.php', function() {
    $.livereload.reload();
  });
});

gulp.task('default', ['rev', 'less', 'js', 'layui', 'layui_src', 'plupload']);