forked from yanghuayi/jq-development-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
98 lines (87 loc) · 2.56 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
var gulp = require('gulp'),
less = require('gulp-less'),
autoprefixer = require('gulp-autoprefixer'),
runSequence = require('run-sequence'),
del = require('del'),
concat = require('gulp-concat'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify');
var csso = require('gulp-csso');
var gutil = require('gulp-util');
var plumber = require('gulp-plumber');
var connect = require('gulp-connect');
var gulpCopy = require('gulp-file-copy');
var order = require('gulp-order');
var smushit = require('gulp-smushit');
function errrHandler( e ){
// 控制台发声,错误时beep一下
gutil.beep();
gutil.log( e );
}
gulp.task('less',function(){
return gulp.src('less/main.less')
.pipe(plumber())
.pipe(less())
.pipe(csso())
.pipe(autoprefixer({
browsers: ['last 2 versions', 'Android >= 4.0'],
cascade: true,
remove: true
}))
.pipe(gulp.dest('dist/css'));
});
gulp.task('images', function() {
return gulp.src('images/**/*')
.pipe(smushit({ verbose: true}))
.pipe(gulp.dest('dist/images'))
});
gulp.task('clean', function() {
return del(['dist/*', '!dist/.git'], {dot: true});
});
//使用connect启动一个Web服务器
gulp.task('connect', function () {
connect.server({
root: '',
livereload: true,
port: 3000
});
});
gulp.task('copy', function () {
gulp
.src([])
.pipe(gulp.dest('js'));
});
gulp.task('copyFonts', function () {
gulp
.src(['fonts/*'])
.pipe(gulp.dest('dist/fonts'));
});
gulp.task('html', function () {
gulp.src('*.html')
.pipe(connect.reload());
});
gulp.task('minifyjs', function() {
return gulp.src('js/*.js')
.pipe(order([
'jquery.1.11.1.min.js',
'*.js'
]))
.pipe(concat('main.js')) //合并所有js到main.js
.pipe(gulp.dest('dist/js')) //输出main.js到文件夹
.pipe(rename({suffix: '.min'})) //rename压缩后的文件名
.pipe(uglify().on('error', function (e) {
console.log(e);
})) //压缩
.pipe(gulp.dest('dist/js')); //输出
});
// 构建任务
gulp.task('build', function(cb) {
runSequence('clean', ['copy','copyFonts','less','images','minifyjs','connect','html'], cb);
});
gulp.task('watch',function(){
gulp.watch('less/**/*.less',['less','html']);
gulp.watch('images/**/*.{png,jpg,gif}',['images']);
gulp.watch('js/*.js',['minifyjs']);
gulp.watch(['*.html'], ['html']);
});
gulp.task('default',['build', 'watch']);