-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
97 lines (78 loc) · 2.46 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
var webpackConfig = require('./scripts/webpack.config.js');
var webpackProConfig = require('./scripts/webpack.pro.config.js');
var webpack = require('gulp-webpack');
var uglify = require('gulp-uglify');
var shell = require('gulp-shell');
var path = require('path');
var gulp = require('gulp');
var fs = require('fs');
var mcss = require('gulp_mcss');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var path = require('path');
var process = require('child_process');
var exec = process.exec;
var child;
var count = 0;
gulp.task('webpack', [], createWebpackTask());
gulp.task('eslint', shell.task([ 'eslint ./src']));
// gulp.task('build', ['eslint','webpack']);
gulp.task('build', ['webpack']);
gulp.task('mcss', function(){
gulp.src(['src/mcss/*.mcss', '!src/mcss/_*.mcss', '!src/mcss/variables.mcss'])
.pipe(mcss({
format: 3,
importCSS: true
// pathes: ['src/webapp/src/js/lib']
}))
.pipe(gulp.dest('public/css'));
});
gulp.task('watch', ['watch_mcss', 'webpackWatch']);
gulp.task('watch_mcss', function() {
gulp.watch('src/mcss/**/*.mcss', {exclude: 'src/mass/'},['mcss']);
});
function createWebpackTask(watch){
var baseConfig = watch? webpackConfig: webpackProConfig;
var config = Object.assign({ }, baseConfig, {
watch: watch,
devtool: watch? 'source-map': undefined,
})
return function(){
gulp.src("src/index.js")
.pipe(webpack(config, null, function(){
if (count < 2) {
count++;
return;
}
reload();
}))
.pipe(gulp.dest('./WEB-INF'))
.pipe(gulp.dest('./public'))
.on("error", function(err){
throw err
});
return;
}
}
gulp.task('webpackWatch', [], createWebpackTask(true));
gulp.task('browserSync', function() {
browserSync({
proxy: 'localhost:8080'
});
});
gulp.task('server', function() {
if(child) {
child.kill();
} else {
setTimeout(function () {
child = exec('nei server', {cwd: path.join(__dirname, './')}, function(err, stdout, stderr) {
if (err) throw err;
console.log(stdout, stderr);
});
},1000);
}
});
// 本地nei开发
gulp.task('default', ['server', 'mcss', 'watch']);
// 调试后端接口
gulp.task('interface', ['mcss', 'watch', 'browserSync']);