-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathpack
290 lines (184 loc) · 6.49 KB
/
pack
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
var gulp = require('gulp'),
concat = require('gulp-concat'),
less = require('gulp-less'),
minifyCss = require('gulp-minify-css'),
minify = require('gulp-minify'),
zip = require('gulp-zip'),
moment = require("moment"),
ftp = require('gulp-ftp'),
git = require('gulp-git'),
runSequence = require('run-sequence'),
argv = require('minimist')(process.argv.slice(2)),
argv = require('minimist')(process.argv.slice(2)),
del = require('del'),
uglify = require('gulp-uglify'),
htmlmin = require('gulp-htmlmin'),
ngAnnotate = require('gulp-ng-annotate');
var path = {
input: {
html: ['src/app/*.html'],
js: ['src/app/js/*.js'],
less: ['src/app/less/*.less'],
image: ['src/app/image/*'],
fonts: ['src/app/fonts/*'],
plugins: ['src/plugins/**/*']
},
output: {
dist: 'dist',
plugins: 'dist/plugins'
}
}
gulp.task('commit', function(){
return gulp.src('./demo/**/*')
.pipe(git.add())
.pipe(git.commit());
});
gulp.task('checkout',[commit], function () {
gitTag = argv.tag;
git.checkout(gitTag, function (err) {
if (err) throw err;
});
})
//压缩html
gulp.task('html', function () {
var options = {
removeComments: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeEmptyAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
minifyJS: true,
minifyCSS: true
};
return gulp.src(config.input.html)
.pipe(htmlmin(options))
.pipe(gulp.dest(config.output.dist))//gulp dest是输出
});
//压缩合并JS
gulp.task('js', function (done) {
return gulp.src(config.input.js)
.pipe(ngAnnotate({single_quotes: true}))
.pipe(uglify())
.pipe(concat('index.min.js'))
.pipe(gulp.dest(config.output.dist))
});
gulp.task('zip_new', function () {
var timeStamp = moment().format("YYYY-MM-D_HH-mm-ss_");
return gulp.src(config.input.zip)
.pipe(zip("dist_" + timeStamp + ".zip"))
.pipe(gulp.dest(config.output.dist));
});
//发送至指定服务器
gulp.task('ftp', function () {
gulp.src("dist_zip/*")
.pipe(ftp({
host: 'someHost',
port: 21,
//user: 'anonymous',
//pass:null,
remotePath: "somePath/"
}));
});
//一键打包
gulp.task('publish', function (callback) {
runSequence(['html', 'js','less', 'copy'],'zip_new',ftp,callback);
});
///////////////////////////////////////////////////////////
//import gulp from 'gulp';
var gulp = require('gulp');
import fileConfig from 'FileConfig';
// 说明
gulp.task('help', function () {
console.log(' gulp build 文件打包');
console.log(' gulp watch 文件监控打包');
console.log(' gulp help gulp参数说明');
console.log(' gulp server 测试server');
console.log(' gulp -p 生产环境(默认生产环境)');
console.log(' gulp -d 开发环境');
console.log(' gulp -m <module> 部分模块打包(默认全部打包)');
});
/* 默认 */
gulp.task('default', function () {
gulp.start('help');
});
/* 载入工具 */
var argv = require('yargs').argv,
_ = require('lodash'),
path = require('path');
//创建任务
gulp.task('build', function () {
var evr = argv.p || !argv.d; //生产环境为true,开发环境为false,默认为true
var mod = argv.m || 'all';//模块明,默认为全部
/* 路径初始化 */
fileConfig.init(evr);
//console.log(' '+evr)
//console.log(' '+mod)
});
gulp.task('clean', function() {
if(mod === 'all') {
var clean_path = path.join( evr&& basePath.production || basePath.develop, '/');
return gulp.src([clean_path], {read:false})
.pipe(clean());
}
});
// 载入外挂
var browserify = require('browserify'),//这里用不上,管理js依赖的
source = require('vinyl-source-stream'),//同样这里用不上,和上面那个一起的
uglify = require('gulp-uglify'),//混淆js
clean = require('gulp-clean'),//清理文件
notify = require('gulp-notify'),//加控制台文字描述用的
buffer = require('vinyl-buffer'),
less = require('gulp-less'),//转换less用的
autoprefixer = require('gulp-autoprefixer'),//增加私有变量前缀
minifycss = require('gulp-minify-css'),//压缩
concat = require('gulp-concat'),//合并
fileinclude = require('gulp-file-include'),// include 文件用
template = require('gulp-template'),//替换变量以及动态html用
rename = require('gulp-rename'),//重命名
webserver = require('gulp-webserver'),//一个简单的server,用python的SimpleHttpServer会锁文件夹
imagemin = require('gulp-imagemin'),//图片压缩
gulpif = require('gulp-if'),//if判断,用来区别生产环境还是开发环境的
rev = require('gulp-rev'),//加MD5后缀
revReplace = require('gulp-rev-replace'),//替换引用的加了md5后缀的文件名,修改过,用来加cdn前缀
addsrc = require('gulp-add-src'),//pipeline中途添加文件夹,这里没有用到
del = require('del'),//也是个删除···
vinylPaths = require('vinyl-paths'),//操作pipe中文件路径的,加md5的时候用到了
runSequence = require('run-sequence');//控制task顺序
/* 打包方法 */
var teemoGulp = {
/* html打包 */
buildHtml: function () {
var src = arguments[0], dest = arguments[1], flag = arguments[2], options = arguments[3];
return gulp.src(src)
.pipe(fileinclude({
basepath: basePath.source
}))
.pipe(template(options, {
//interpolate: /\{-([\s\S]+?)-\}/g
}))
.pipe(gulp.dest(dest))
},
/* css 打包 */
buildCss: function () {
},
/* js打包 */
buildJs: function () {
var src = arguments[0], dest = arguments[1], flag = arguments[2]
return gulp.src(src)
.pipe(gulp.dest(dest))
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(dest));
},
/* img打包 */
buildImg: function () {
var src = arguments[0], dest = arguments[1], flag = arguments[2]
return gulp.src(src)
.pipe(gulpif(flag, imagemin()))
.pipe(gulp.dest(dest));
},
/* md5打包 */
buildMd5: function () {
}
}