gulpfile.js 1.74 KB
/**
 * gulp file 执行compass解析,spm build以及文件合并压缩等
 * author: xuqi(qi.xu@yoho.cn)
 * date; 2015/3/27
 */
var gulp = require('gulp'),
    concat = require('gulp-concat'),
    compass = require('gulp-compass'),
    exec = require('child_process').exec,
    server = require('gulp-develop-server');

// 启动
gulp.task('default', ['server', 'server:restart', 'compass-watch', 'compass']);

// start express server
gulp.task('server', function() {
    server.listen({
        path: 'app.js'
    });
});

// restart server if app.js changed
gulp.task('server:restart', function() {
    gulp.watch([
        'app.js', 'views/**/*.html', 'views/controller/*.js', 
        'layouts/*.html', 'public/css/*.css'], server.restart);
});

//compass 解析压缩合并
gulp.task('compass-watch', function() {
    gulp.watch('public/sass/*.scss', ['compass']);
});

gulp.task('compass', function() {
    gulp.src('public/sass/*.scss')
        .pipe(
            compass({
                config_file: 'config.rb',
                css: 'public/css',
                sass: 'public/sass'
            })
        )
});

//spm build
gulp.task('build', function() {
    exec('spm build --include all', function() {
        exec('gulp build-debug');
        exec('gulp build-production');
    });
});

//generate all-debug.js for development ENV
gulp.task('build-debug', function() {
    gulp.src(['public/lib/sea.js', 'dist/yohobuy-mobile/1.0.0/index-debug.js'])
        .pipe(concat('all-debug.js'))
        .pipe(gulp.dest('public/dist'))
});

//generate all.js for production ENV
gulp.task('build-production', function() {
    gulp.src(['public/lib/sea.js', 'dist/yohobuy-mobile/1.0.0/index.js'])
        .pipe(concat('all.js'))
        .pipe(gulp.dest('public/dist'))
});