-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
68 lines (56 loc) · 1.55 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
var gulp = require('gulp');
var webpack = require('webpack');
var nodemon = require('nodemon');
var path = require('path');
var clientConfig = require('./webpack.client.config.js');
var serverConfig = require('./webpack.server.config.js');
if (process.env.NODE_ENV !== 'production') {
clientConfig.devtool = '#eval-source-map';
clientConfig.debug = true;
serverConfig.devtool = '#eval-source-map';
serverConfig.debug = true;
}
function onBuild(done) {
return function(err, stats) {
if(err) {
console.log('Error', err);
}
else {
console.log(stats.toString());
}
if(done) {
done();
}
}
}
gulp.task('client-build', function(done) {
webpack(clientConfig).run(onBuild(done));
});
gulp.task('client-watch', ['client-build'], function() {
webpack(clientConfig).watch(100, onBuild());
});
gulp.task('server-build', ['client-build'], function(done) {
webpack(serverConfig).run(onBuild(done));
});
gulp.task('server-watch', ['server-build', 'client-build'], function() {
webpack(serverConfig).watch(100, function(err, stats) {
onBuild()(err, stats);
nodemon.restart();
});
});
gulp.task('build', ['client-build', 'server-build']);
gulp.task('watch', ['client-watch', 'server-watch']);
gulp.task('dev', ['server-watch', 'client-watch'], function() {
nodemon({
execMap: {
js: 'node'
},
script: path.join(__dirname, 'build/index.js'),
ignore: ['*'],
watch: ['foo/'],
ext: 'noop'
}).on('restart', function() {
console.log('Restarted!');
});
});
gulp.task('default', ['build']);