-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgulpfile.js
66 lines (55 loc) · 1.24 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
const gulp = require('gulp');
const webpack = require('webpack');
const nodemon = require('nodemon');
const forever = require('forever');
const path = require('path');
let config = null;
if(process.env.NODE_ENV !== 'production'){
config = require('./webpack.dev.js');
} else {
config = require('./webpack.prod.js');
}
function onBuild(done){
return function(err, stats){
if(err){
console.log("Error", err);
} else {
console.log(stats.toString());
}
if(done){
done();
}
};
}
gulp.task('build', function(done){
webpack(config).run(onBuild(done));
});
gulp.task('watch', function(){
webpack(config).watch(100, function(err, stats){
onBuild()(err, stats);
nodemon.restart();
});
});
if(process.env.NODE_ENV !== 'production'){
gulp.task('run', ['watch'], function(){
nodemon({
execMap:{
js:'node'
},
script: path.join(__dirname, 'dist/server'),
ignore:['*'],
watch:['foo/'],
ext: 'noop'
}).on('restart', function(){
console.log("Restarted");
});
});
} else {
gulp.task('run', function(){
const options= {
watch: false,
sourceDir: path.join(__dirname, 'dist')
};
forever.start('server.js', options);
});
}