-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
108 lines (92 loc) · 3.1 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
99
100
101
102
103
104
105
106
107
108
var gulp = require('gulp');
var connect = require('gulp-connect');
// var inject = require('gulp-inject');
var del = require('del'); //用来删除文件的
var sass = require('gulp-sass');
var jade = require('gulp-jade');
var babel = require('gulp-babel');
var browserify = require('gulp-browserify');
gulp.task('webserver', function() {
connect.server({
root: 'site', //程序入口处,自动为这个文件夹下的Index.html
livereload: true
});
});
gulp.task('clean', function() {
return del(['site']);
});
gulp.task('sass', function() {
gulp.src('style.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('styles'))
.pipe(connect.reload()); //用来实现更改自动刷新
});
//['sass']指sass这个task完成之后再执行css这个task。
gulp.task('css', ['sass'], function() {
gulp.src('styles/*.css')
.pipe(gulp.dest('site/styles'))
.pipe(connect.reload());
});
// 加入了babel和browserify,可以编写ES6
gulp.task('js', function() {
gulp.src('scripts/*.js')
.pipe(babel({
presets: ['es2015']
}))
.pipe(browserify())
.pipe(gulp.dest('site/scripts'))
.pipe(connect.reload());
});
gulp.task('staticFiles', function() {
gulp.src(['static/*.js', 'static/*.css', 'static/*.map', 'static/*.png'])
.pipe(gulp.dest('site/static'));
})
gulp.task('staticSlick', function() {
gulp.src(['static/slick/*.css', 'static/slick/*.js', 'static/slick/*.gif'])
.pipe(gulp.dest('site/static/slick'));
})
gulp.task('staticPicsExport', function() {
gulp.src(['static/pictures/export/*'])
.pipe(gulp.dest('site/static/pictures/export'));
})
gulp.task('staticPicsAssets', function() {
gulp.src(['static/pictures/assets/*', 'static/pictures/assets/*/*'])
.pipe(gulp.dest('site/static/pictures/assets'));
})
gulp.task('staticFonts', function() {
gulp.src(['static/fonts/*'])
.pipe(gulp.dest('site/fonts'));
})
// gulp-inject自动注入依赖,这个项目中赞不需要
// gulp.task('inject', ['sass', 'css', 'js'], function() {
// var target = gulp.src('./layout.jade');
// var sources = gulp.src(['./styles/*.css', './scripts/*.js'], {read: false});
// return target.pipe(inject(sources))
// .pipe(gulp.dest('./'));
// });
//index.jade预编译为site/index.html
gulp.task('index', function() {
gulp.src('index.jade')
.pipe(jade())
.pipe(gulp.dest('site'))
.pipe(connect.reload());
});
gulp.task('jade', function() {
gulp.src('layouts/*.jade')
.pipe(jade())
.pipe(gulp.dest('site/layouts'))
.pipe(connect.reload());
})
gulp.task('ico', function() {
gulp.src('favicon.ico')
.pipe(gulp.dest('site'));
})
gulp.task('watch', function() {
// gulp.watch('index.jade', ['index']);
gulp.watch('layouts/*.jade', ['jade']);
gulp.watch('styles/*.css', ['css']);
gulp.watch('scripts/*.js', ['js']);
// gulp.watch('style.scss', ['sass']);
});
gulp.task('default', ['webserver', 'clean', 'sass', 'css', 'js', 'staticFiles', 'staticSlick', 'staticPicsExport', 'staticPicsAssets', 'staticFonts', 'index', 'jade', 'ico', 'watch']);
gulp.task('build', ['sass', 'css', 'js', 'staticFiles', 'staticSlick', 'staticPicsExport', 'staticPicsAssets', 'staticFonts', 'index', 'jade', 'ico']);