forked from easemob/kefu-webim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·178 lines (158 loc) · 4.43 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
以下文件老版本会引用到,不能在服务器上彻底删除,但如果需要的话可以在当前代码分支中删除
/static/js/em-open.js
/static/js/em-transfer.js
/transfer.html
/static/img/file_download.png
*/
var debug = false;
const VERSION = '43.12.017';
const gulp = require('gulp');
const postcss = require('gulp-postcss');
const sass = require('gulp-sass');
const cssnano = require('cssnano');
const autoprefixer = require('autoprefixer');
const minifycss = require('gulp-minify-css');
const jshint = require('gulp-jshint');
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');
const clean = require('gulp-clean');
const minifyHtml = require("gulp-minify-html");
const template = require('gulp-template');
//clean
gulp.task('clean', function() {
gulp.src([
'static/css/im.css',
'static/js/main.js',
'im.html',
'easemob.js'
], {
read: false
}
)
.pipe(clean({force: true}));
});
//minifyHtml
gulp.task('minifyHtml', function () {
gulp.src('static/tpl/im.html')
.pipe(minifyHtml())
.pipe(template({ WEBIM_PLUGIN_VERSION: VERSION }))
.pipe(gulp.dest('.'));
});
//postcss
gulp.task('cssmin', function() {
gulp.src([
'static/css/src/global.scss',
'static/css/src/icon.scss',
'static/css/src/header.scss',
'static/css/src/body.scss',
'static/css/src/chat.scss',
'static/css/src/send.scss',
'static/css/src/theme.scss',
'static/css/src/ui.scss',
'static/css/src/mobile.scss',
])
.pipe(concat('im.css'))
.pipe(template({ WEBIM_PLUGIN_VERSION: VERSION }))
.pipe(sass())
.pipe(postcss([
autoprefixer({
browsers: ['ie >= 8', 'ff >= 10', 'Chrome >= 15', 'iOS >= 7', 'Android >= 4.4.4']
}),
cssnano({
discardComments: {
removeAll: true,
},
mergeRules: false,
zindex: false,
reduceIdents: false,
}),
]))
.pipe(gulp.dest('static/css/'));
});
//jshint
gulp.task('lint', function() {
gulp.src([
'static/js/src/*.js',
'static/js/src/modules/*.js',
])
.pipe(jshint({
"laxcomma" : true,
"laxbreak" : true,
"expr" : true
}))
.pipe(jshint.reporter());
});
//compress
gulp.task('combineJs', function() {
var main = gulp.src([
'static/js/src/sdk/strophe.js',
// 'static/js/src/sdk/strophe-1.2.8.js',
'static/js/src/sdk/adapter.js',
'static/js/src/sdk/webim.config.js',
'static/js/src/sdk/websdk-1.4.6.js',
'static/js/src/sdk/easemob.im-1.1.1.js',
'static/js/src/sdk/webrtc-1.4.4.js',
'static/js/src/modules/polyfill.js',
'static/js/src/modules/utils.js',
'static/js/src/modules/const.js',
'static/js/src/modules/ajax.js',
'static/js/src/modules/transfer.js',
'static/js/src/modules/api.js',
'static/js/src/modules/eventsEnum.js',
'static/js/src/modules/autogrow.js',
'static/js/src/modules/message.js',
'static/js/src/modules/paste.js',
'static/js/src/modules/leaveMessage.js',
'static/js/src/modules/satisfaction.js',
'static/js/src/modules/imgView.js',
'static/js/src/modules/uploadShim.js',
'static/js/src/modules/wechat.js',
'static/js/src/modules/site.js',
'static/js/src/modules/channel.js',
'static/js/src/modules/ui.js',
'static/js/src/modules/videoChat.js',
'static/js/src/modules/chat.js',
'static/js/src/modules/eventCollector.js',
'static/js/src/init.js'
])
.pipe(concat('main.js'));
debug || main.pipe(uglify());
main.pipe(template({ WEBIM_PLUGIN_VERSION: VERSION }))
.pipe(gulp.dest('static/js/'));
var ejs = gulp.src([
'static/js/src/modules/utils.js',
'static/js/src/modules/transfer.js',
'static/js/src/modules/eventsEnum.js',
'static/js/src/modules/notify.js',
'static/js/src/modules/titleSlide.js',
'static/js/src/modules/iframe.js',
'static/js/src/userAPI.js',
])
.pipe(concat('easemob.js'));
debug || ejs.pipe(uglify());
ejs.pipe(template({ WEBIM_PLUGIN_VERSION: VERSION }))
.pipe(gulp.dest('.'));
var transfer = gulp.src([
'static/js/src/modules/ajax.js',
'static/js/src/modules/transfer.js',
'static/js/src/modules/api.js',
])
.pipe(concat('em-transfer.js'));
debug || transfer.pipe(uglify());
transfer.pipe(gulp.dest('static/js/'));
});
//build default debug = false
gulp.task('build', ['clean'], function() {
gulp.start('cssmin', 'combineJs', 'minifyHtml');
});
gulp.task('dev', function(){
debug = true;
gulp.start('build');
})
gulp.task('watch', function() {
gulp.start('dev');
gulp.watch(['static/js/src/*.js', 'static/js/src/*/*.js'], ['combineJs']);
gulp.watch(['static/css/src/*.scss'], ['cssmin']);
gulp.watch(['static/tpl/im.html'], ['minifyHtml']);
});