-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathgulpfile.js
152 lines (124 loc) · 4.98 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var cleanCSS = require('gulp-clean-css');
// 串行执行任务
var gulpSequence = require('gulp-sequence');
// 头部注释
var header = require('gulp-header');
var pkg = require('./package.json');
var banner = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @author <%= pkg.homepage %>',
' */',
''].join('\n');
var debugPath = './dist/_debug/';
var releasePath = './dist/';
// 下拉刷新核心文件合并
gulp.task('core_concat', function() {
return gulp.src(['./src/core/pulltorefresh.iscroll.probe.js', './src/core/pulltorefresh.js', './src/core/pulltorefresh.core.js'])
.pipe(concat('pulltorefresh.core.js'))
.pipe(gulp.dest(debugPath));
});
// 打包skin-defult
gulp.task('pack_skin_default', ['core_concat'], function() {
return gulp.src([debugPath + 'pulltorefresh.core.js', './src/pulltorefresh.skin.default.js'])
.pipe(concat('pulltorefresh.skin.default.js'))
.pipe(gulp.dest(debugPath));
});
// 打包skin-type1
gulp.task('pack_skin_type1', ['core_concat'], function() {
return gulp.src([debugPath + 'pulltorefresh.core.js', './src/pulltorefresh.skin.type1.js'])
.pipe(concat('pulltorefresh.skin.type1.js'))
.pipe(gulp.dest(debugPath));
});
// 打包skin-type2
gulp.task('pack_skin_type2', ['core_concat'], function() {
return gulp.src([debugPath + 'pulltorefresh.core.js', './src/pulltorefresh.skin.type2.js'])
.pipe(concat('pulltorefresh.skin.type2.js'))
.pipe(gulp.dest(debugPath));
});
// 打包skin-type3
gulp.task('pack_skin_type3', ['core_concat'], function() {
return gulp.src([debugPath + 'pulltorefresh.core.js', './src/pulltorefresh.skin.type3.js'])
.pipe(concat('pulltorefresh.skin.type3.js'))
.pipe(gulp.dest(debugPath));
});
// 打包skin-type4
gulp.task('pack_skin_type4', ['core_concat'], function() {
return gulp.src([debugPath + 'pulltorefresh.core.js', './src/pulltorefresh.skin.type4.js'])
.pipe(concat('pulltorefresh.skin.type4.js'))
.pipe(gulp.dest(debugPath));
});
// 打包skin-type5
gulp.task('pack_skin_type5', ['core_concat'], function() {
return gulp.src([debugPath + 'pulltorefresh.core.js', './src/pulltorefresh.skin.type5.js'])
.pipe(concat('pulltorefresh.skin.type5.js'))
.pipe(gulp.dest(debugPath));
});
// 打包skin-native
gulp.task('pack_skin_native', function() {
return gulp.src(['./src/pulltorefresh.skin.native.js'])
.pipe(concat('pulltorefresh.skin.native.js'))
.pipe(gulp.dest(debugPath));
});
// 打包bizlogic-impl
gulp.task('pack_bizlogic_impl', function() {
return gulp.src(['./src/core/handedata.js', './src/pulltorefresh.bizlogic.impl.js'])
.pipe(concat('pulltorefresh.bizlogic.impl.js'))
.pipe(gulp.dest(debugPath));
});
// 打包bizlogic-impl
gulp.task('pack_bizlogic_impl2', function() {
return gulp.src(['./src/core/handedata.js', './src/pulltorefresh.bizlogic.impl2.js'])
.pipe(concat('pulltorefresh.bizlogic.impl2.js'))
.pipe(gulp.dest(debugPath));
});
// 打包 css以及静态资源
gulp.task('pack_resources', function() {
return gulp.src(['./src/css/**/*'])
.pipe(gulp.dest(debugPath + 'css/'));
});
// 压缩发布的源文件
gulp.task('js_uglify', function() {
return gulp.src([debugPath + '**/*.js', '!'+ debugPath + '**/*.min.js'])
.pipe(uglify())
// 压缩时进行异常捕获
.on('error', function(err) {
console.log('line number: %d, message: %s', err.lineNumber, err.message);
this.end();
})
// .pipe(rename({
// suffix: '.min'
// }))
.pipe(header(banner, { pkg : pkg } ))
.pipe(gulp.dest(releasePath));
});
// 压缩发布 css
gulp.task('clean_css', function() {
return gulp.src([debugPath + '**/*.css', '!'+ debugPath + '**/*.min.css'])
.pipe(cleanCSS())
// .pipe(rename({
// suffix: '.min'
// }))
.pipe(header(banner, { pkg : pkg } ))
.pipe(gulp.dest(releasePath));
});
// 压缩发布 图片资源,暂时不压缩
gulp.task('resource_uglify', function() {
return gulp.src([debugPath + '**/*', '!'+ debugPath + '**/*.css', '!'+ debugPath + '**/*.js'])
.pipe(gulp.dest(releasePath));
});
gulp.task('pack_debug', ['pack_skin_default', 'pack_skin_type1', 'pack_skin_type2', 'pack_skin_type3', 'pack_skin_type4', 'pack_skin_type5', 'pack_skin_native', 'pack_bizlogic_impl', 'pack_bizlogic_impl2', 'pack_resources']);
gulp.task('pack_release', ['js_uglify', 'clean_css', 'resource_uglify']);
gulp.task('default', gulpSequence('pack_debug', 'pack_release'));
// 看守
gulp.task('watch', function() {
// 看守所有位在 dist/ 目录下的档案,一旦有更动,便进行重整
// gulp.watch([config.src+'/gulpWatch.json']).on('change', function(file) {
// console.log("改动");
// });
gulp.watch('./src/**/*', ['default']);
});