-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
123 lines (101 loc) · 3.33 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
var gulp = require("gulp");
var webpack = require("webpack");
var uglify = require('gulp-uglify');
var run_sequence = require('run-sequence');
var webpack_config_; //模块weboack config配置对象组
var proName;
function registerTasks(proName_) {
proName = proName_;
webpack_config_ = require("./webpack.config");
//src模块任务
gulp.task('moduleTasks', function() {
doWebPackTask(webpack_config_);
});
gulp.task('watch', function(callback) {
gulp.watch('./src/**', function(file) {
console.log(file);
var path = file.path;
path = path.replace(/\\/g, "/"); //path格式 /a/b/c/d
if (path.search('/src') == -1) {
return;
}
if (path.search('/yuepian') != -1) {
run_sequence(['yuepian']);
return;
}
webpackConfigByPath(path);
function webpackConfigByPath(path) {
var taskPath;
for (var i = 0; i < webpack_config_.length; i++) {
taskPath = webpack_config_[i].path.join('/');
if (path.search(taskPath) != -1) {
doWebPackTask(webpack_config_[i]);
break;
}
}
}
});
callback();
});
}
// 特殊配置 end
gulp.task('copyErrorPage', function() {
gulp.src('./src/system/**').pipe(gulp.dest('./views/system'));
});
//启动命令
gulp.task('start', function(callback) {
require('./bin/www');
});
gulp.task("all", function() {
registerTasks();
run_sequence(['copyErrorPage', 'moduleTasks'], function() {});
});
gulp.task('devAll', function() {
registerTasks();
run_sequence(['copyErrorPage', 'moduleTasks', 'watch', 'start']);
});
//
//非顺序执行webpack
function doWebPackTask(cfgObj) {
var time1 = new Date();
if (cfgObj instanceof Array) {
doWebPackTaskItem(cfgObj[0], 0);
} else {
doWebPackTaskItem(cfgObj);
}
function doWebPackTaskItem(cfg, i) {
if (proName && cfg.path.indexOf(proName) == -1) {
if ((i || i == 0) && cfgObj[i + 1]) { doWebPackTaskItem(cfgObj[i + 1], i + 1); } else {
finishTaskLog('all after ' + (new Date() - time1) / 1000 + "s");
console.log("no Errors!");
}
return;
}
webpack(cfg.config, function(error, status) {
if (error) errorLog('webpack', error);
if (status.compilation.errors.length) {
console.log(status.compilation.errors);
return;
}
finishTaskLog(cfg.path);
if ((i || i == 0) && cfgObj[i + 1]) { doWebPackTaskItem(cfgObj[i + 1], i + 1); } else {
finishTaskLog('all after ' + (new Date() - time1) / 1000 + "s");
console.log("no Errors!");
}
});
}
}
function finishTaskLog(path) {
if (path instanceof Array)
console.log("finished: " + path.join(" | "));
else console.log("finished: " + path);
}
function startTaskLog(path) {
if (path instanceof Array)
console.log("started: " + path.join(" | "));
else console.log("started: " + path);
}
function errorLog(type, err) {
console.log("Error! (by " + type + ")");
console.log(err);
}