-
Notifications
You must be signed in to change notification settings - Fork 23
/
gulpfile.js
113 lines (101 loc) · 2.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
var gulp = require('gulp')
var uglify = require('gulp-uglify')
var minifyCss = require('gulp-minify-css')
var less = require('gulp-less')
var clean = require('gulp-clean')
var RevAll = require('gulp-rev-all')
var imagemin = require('gulp-imagemin')
var qiniu = require('gulp-qiniu')
try {
var qiniuConfig = require('../../../.qiniu.json')
var digitaloceanConfig = require('../../../.digitalocean.json')
} catch(e) {
}
var scp = require('gulp-scp2')
gulp.task('less', function () {
return gulp.src('src/less/Frontend-Magazine.less')
.pipe(less())
.pipe(gulp.dest('src/css/'))
})
gulp.task('min-script', function () {
return gulp.src('src/js/**/*.js')
.pipe(uglify().on('error', function(e) { console.log('\x07',e.message);}))
.pipe(gulp.dest('dist/js/'))
})
gulp.task('min-style', ['less'], function () {
return gulp.src('src/css/**/*.css')
.pipe(minifyCss())
.pipe(gulp.dest('dist/css/'))
})
gulp.task('min-images', function () {
return gulp.src('src/images/**/*.{jpg,gif,png,JPG,jpeg}')
.pipe(imagemin({
progressive: true
}))
.pipe(gulp.dest('dist/images/'))
})
gulp.task('copy', function () {
return gulp.src([
'src/**',
'!src/css/**',
'!src/images/**',
'!src/js/**',
'!src/less/**',
'!src/_posts/archive/**',
'!src/_posts/doing/**',
'!src/_posts/todo/**'
])
.pipe(gulp.dest('dist/'))
})
gulp.task('clean', function () {
return gulp.src([
'dist',
'rev',
'_site'
], {read: false})
.pipe(clean());
})
gulp.task('dist', ['min-script', 'min-style', 'min-images', 'copy'])
gulp.task('build', ['dist'], function () {
var revAll = new RevAll({
prefix: 'http://7xrvqo.com1.z0.glb.clouddn.com',
dontRenameFile: ['.html', '.xml', '.md', '.yml', '.ico'],
dontUpdateReference: ['.html', '.xml', '.md', '.yml', '.ico']
})
return gulp.src('dist/**')
.pipe(revAll.revision())
.pipe(gulp.dest('rev'))
})
gulp.task('digitalocean', function () {
return gulp.src([
'_site/**',
'!_site/css/**',
'!_site/fonts/**',
'!_site/images/**',
'!_site/js/**'
], {base: '_site'})
.pipe(scp(digitaloceanConfig))
.on('error', function(err) {
console.log(err)
})
})
gulp.task('watch', function () {
return gulp.watch('src/less/**/*.less', ['less'])
});
gulp.task('qiniu', function () {
return gulp.src([
'rev/css/**',
'rev/fonts/**',
'rev/js/**',
'rev/images/**'
], {base: 'rev'})
.pipe(qiniu({
accessKey: qiniuConfig.accessKey,
secretKey: qiniuConfig.secretKey,
bucket: "qianduan",
private: false
}, {
dir: '/',
concurrent: 10
}))
})