Yblog

Feiye 的个人日记 WIKI

用户工具


/ * Created by Yefei on 2017/1/31. */ var path = require('path'); var gulp = require('gulp'); var gutil = require('gulp-util'); var concat = require('gulp-concat'); var less = require('gulp-less'); var uglify = require('gulp-uglify'); var minifycss = require('gulp-clean-css'); var runSequence = require('run-sequence'); var clean = require('gulp-clean'); var distFolder = path.join(dirname, '..', 'public', 'assets'); var distCssFolder = path.join(distFolder, 'css'); var distJsFolder = path.join(distFolder, 'js'); var watchmode = gutil.env._.length && gutil.env._[0] == 'watch'; var watchCache = {}; var watchfolders = ['js//*', 'style//*']; var corejs = [ './js/lib/jquery.js', './js/core.js' ]; var lesss = [ './style/core.less' ]; gulp.task('default', ['dist']); gulp.task('dist', function (done) { runSequence('dist-style', 'dist-js', 'dist-minify', function(){ done(); }); }); gulp.task('watch', function(done) { gulp.watch(watchfolders, function(files) { runSequence('dist'); }); }); gulp.task('dist-style', function(done) { gulp.src(lesss).pipe(less({paths:dirname})).pipe(gulp.dest(distCssFolder)).on('end', function(){ done(); }); }); gulp.task('dist-js', function(done) { gulp.src(corejs).pipe(concat('core.js')).pipe(gulp.dest(distJsFolder)).on('end', function(){ done(); }); }); gulp.task('dist-minify', function(done) { if (watchmode) { return done(); } minify css gulp.src(path.join(distCssFolder, '', '*.css')).pipe(minifycss()).pipe(gulp.dest(distCssFolder)).on('end', function(){ minify js gulp.src(path.join(distJsFolder, '**', '*.js')).pipe(uglify()).pipe(gulp.dest(distJsFolder)).on('end', function(){ done(); }); }); }); gulp.task('dist-clean', function(done) { gulp.src(distFolder, {read:false}).pipe(clean({force:true})).on('end', function(){ done(); }); });