forked from desenmeng/learning-gulp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
89 lines (80 loc) · 2.08 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
/**
* learning-gulp - gulpfile.js
* Created by mengdesen on 15/4/14.
* Last modified by nieweidong on 2015/04/15
*/
'use strict';
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var shrink = require('gulp-cssshrink');
// 静态文件打包合并
var webpack = require('gulp-webpack');
// 上传七牛sdn
var qn = require('gulp-qn');
// MD5戳
var rev = require('gulp-rev');
var revCollector = require('gulp-rev-collector');
var runSequence = require('run-sequence');
var config = require('./webpack.config');
var qiniu = {
accessKey: '6sBCo463jJOCnBIYX__uy9avZ7C2hj_MHb-ffKAr',
secretKey: '3vPk7fB0HcwL5V9E2AErHuR19HM389eYqdvQcncL',
bucket: 'xdemo',
domain: 'http://7xik9a.com1.z0.glb.clouddn.com'
};
gulp.task('js', function () {
gulp.src('./js')
.pipe(webpack(config))
.pipe(gulp.dest('./build'));
});
gulp.task('css', function () {
gulp.src(['./css/main.css', './css/view.css'])
.pipe(concat('app.css'))
.pipe(gulp.dest('./build'));
});
gulp.task('publish-js', function () {
return gulp.src(['./js'])
.pipe(webpack(config))
.pipe(uglify())
.pipe(rev())
.pipe(gulp.dest('./build'))
.pipe(qn({
qiniu: qiniu,
prefix: 'gmap'
}))
.pipe(rev.manifest())
.pipe(gulp.dest('./build/rev/js'));
});
gulp.task('publish-css', function () {
return gulp.src(['./css/main.css', './css/view.css'])
.pipe(concat('app.css'))
.pipe(shrink())
.pipe(rev())
.pipe(gulp.dest('./build'))
.pipe(qn({
qiniu: qiniu,
prefix: 'gmap'
}))
.pipe(rev.manifest())
.pipe(gulp.dest('./build/rev/css'));
});
gulp.task('watch', function () {
gulp.watch('./css/*.css', ['css']);
gulp.watch('./js/*.js', ['js']);
});
gulp.task('publish-html', function () {
return gulp.src(['./build/rev/**/*.json', './index.html'])
.pipe(revCollector({
dirReplacements: {
'build/': ''
}
}))
.pipe(gulp.dest('./dist/'));
});
gulp.task('publish', function (callback) {
runSequence(
['publish-css', 'publish-js'],
'publish-html',
callback);
});