-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
78 lines (63 loc) · 2.06 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
// gulp 3.9.1
/*
* 老版本的gulp 3.9.1
* 想要控制顺序执行,只能通过依赖的写法,但是依赖中可能有多个任务,我也想让他安装顺序执行,这就蛋疼了
* 但是依赖中的任务都是异步的,
* !!!可以通过gulp-sequence
*
* 新版本的gulp就可以通过parallel(并行) 与 series(串行),很方便的控制顺序
*
*/
const path = require("path");
const gulp = require("gulp");
const gulpSequence = require("gulp-sequence");
const config = require("./config");
// hack module._findPath;
const setAlias = require("./lib/alias");
setAlias(config.paths);
const taskCreators = {
del: require("./tasks/del"),
copy: require("./tasks/copy"),
webpackBuild: require("./tasks/webpack").build,
webpackWatch: require("./tasks/webpack").watch,
server: require("./tasks/server")
};
gulp.task("del:template", function(cb) {
taskCreators.del(config.template.dest)(cb);
});
gulp.task("del:asset", function(cb) {
taskCreators.del(config.asset.dest)(cb);
});
gulp.task("del:webpack", function(cb) {
taskCreators.del(config.webpack.dest)(cb);
});
gulp.task("del", ["del:template", "del:asset", "del:webpack"], function(cb) {
console.log("del all");
cb();
});
gulp.task("asset", function() {
return taskCreators.copy(config.asset)();
});
gulp.task("template", function() {
return taskCreators.copy(config.template)();
});
gulp.task("webpack", function() {
return taskCreators.webpackBuild(config)();
});
// 串行
gulp.task("build", gulpSequence("template", "asset", "webpack"));
// 并行 两种方式
// gulp.task("build", gulpSequence(["template", "asset", "webpack"]));
// gulp.task("build", ["template", "asset", "webpack"]);
gulp.task("watch", function(cb) {
gulp.watch([config.asset.src.patterns], {}, ["asset"]);
gulp.watch([config.template.src.patterns], {}, ["template"]);
taskCreators.webpackWatch(config);
});
gulp.task("dev", gulpSequence("del", "build", "watch"));
gulp.task("server", function(cb) {
taskCreators.build(config)(cb);
});
gulp.task("start", ["del"], function() {
gulp.start("build");
});