-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
120 lines (105 loc) · 3.63 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
109
110
111
112
113
114
115
116
117
118
119
120
var gulp = require('gulp');
var less = require('gulp-less');
var fileInclude = require('gulp-file-include');
var browserSync = require('browser-sync').create();
var RevAll = require('gulp-rev-all');
var imageMin = require('gulp-imagemin');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var minify = require('gulp-minify-css');
var rimraf = require('gulp-rimraf');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
// Folder name config
var serveFolder = './serve';
var distFolder = './dist';
var tmp = './_tmp';
gulp.task('include', function() {
gulp.src('./src/*.html')
.pipe(fileInclude())// https://github.com/coderhaoxin/gulp-file-include
.pipe(gulp.dest(serveFolder));
});
gulp.task('less', function() {
gulp.src('./src/less/app.less')
.pipe(less())
.pipe(postcss([autoprefixer]))
.pipe(gulp.dest(serveFolder + '/css'))
.pipe(browserSync.reload({stream : true})); // http://www.browsersync.io/docs/gulp/
});
gulp.task('serve', ['include', 'less', 'imagemin', 'copyjs', 'copyfiles'], function(){
browserSync.init({ // http://www.browsersync.io/docs/gulp/
server: {
baseDir: serveFolder,
routes: {
"/bower_components": "bower_components"
}
}
});
gulp.watch('./src/**/*.html', ['include']);
gulp.watch('./src/less/**/*.less', ['less']);
gulp.watch('./src/js/**/*.js', ['copyjs']);
gulp.watch('./src/img/**/*', ['imagemin']);
gulp.watch('./src/posts/**/*', ['copyfiles']);
gulp.watch('./src/data/**/*', ['copyfiles']);
gulp.watch(serveFolder + '/*.html').on('change', browserSync.reload);
gulp.watch(serveFolder + '/js/**/*.js').on('change', browserSync.reload);
gulp.watch(serveFolder + '/img/**/*').on('change', browserSync.reload);
gulp.watch(serveFolder + '/posts/**/*').on('change', browserSync.reload);
gulp.watch(serveFolder + '/data/**/*').on('change', browserSync.reload);
});
gulp.task('copyjs', function(){
gulp.src('./src/js/**/*.js')
.pipe(gulp.dest(serveFolder + '/js'));
});
gulp.task('copyfiles', function(){
gulp.src(['./src/fonts/**/*', './src/favicon.ico', './src/bower_components/**/*', './src/posts/**/*', './src/data/**/*'], {base : './src'})
.pipe(gulp.dest(serveFolder));
});
gulp.task('rev', ['compress'], function(){
var revAll = new RevAll(); // https://www.npmjs.com/package/gulp-rev-all
gulp.src(tmp + '/**')
.pipe(revAll.revision())
.pipe(gulp.dest(distFolder))
.pipe(revAll.manifestFile())
.pipe(gulp.dest(distFolder))
.pipe(revAll.versionFile())
.pipe(gulp.dest(distFolder));
});
gulp.task('imagemin', function(){
return gulp.src('src/img/**/*')
.pipe(imageMin({
progressive: true
}))
.pipe(gulp.dest(serveFolder + '/img'));
});
gulp.task('compress', ['minify', 'uglify', 'copyimg']);
gulp.task('minify', function() {
gulp.src(serveFolder + '/css/**/*.css')
.pipe(concat('app.css'))
.pipe(minify({
keepBreaks : true
}))
.pipe(gulp.dest(tmp + '/css'));
});
gulp.task('copyimg', function(){
gulp.src(serveFolder + '/img/**/*')
.pipe(gulp.dest(tmp + '/img'));
});
gulp.task('uglify', function() {
gulp.src(serveFolder + '/js/**/*.js')
.pipe(concat('app.js'))
.pipe(uglify({
compress : {
drop_console : true
}
}))
.pipe(gulp.dest(tmp + '/js'));
});
gulp.task('build', ['rev'], function(){
gulp.src(tmp)
.pipe(rimraf());
});
gulp.task('clean', function() {
gulp.src([tmp, distFolder, serveFolder])
.pipe(rimraf());
});