-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
106 lines (87 loc) · 2.23 KB
/
gulpfile.babel.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
import gulp from 'gulp';
import gutil from 'gulp-util';
import shell from 'gulp-shell';
import nodemon from 'gulp-nodemon';
import del from 'del';
import webpack from 'webpack';
import webpackProdConfig from './server/prod/webpack.config';
import webpackDevConfig from './server/dev/webpack.config';
let BUILD_PATH = './_public';
let production = false;
if (gutil.env.env === 'production') {
production = true;
}
gulp.task('static-generator', shell.task(
'babel-node server/staticGenerator.js', {
env: {
NODE_ENV: production ? 'production': 'development'
}
}
));
gulp.task('ico', () => {
return gulp.src('./client/views/**/*')
.pipe(gulp.dest(BUILD_PATH));
});
gulp.task('images', () => {
return gulp.src('./client/images/**/*')
.pipe(gulp.dest(`${BUILD_PATH}/images/`));
});
gulp.task('data', () => {
return gulp.src('./client/data/*')
.pipe(gulp.dest(`${BUILD_PATH}/data/`));
});
gulp.task('webpack', (cb) => {
let webpackConfig = production ? webpackProdConfig: webpackDevConfig;
webpack(webpackConfig, (err, stats) => {
if (err) {
return cb(err);
}
let jsonStats = stats.toJson();
if (jsonStats.errors.length > 0) {
return cb(jsonStats.errors);
}
if (jsonStats.warnings.length > 0) {
gutil.log(gutil.colors.yellow(jsonStats.warnings));
}
cb();
});
});
gulp.task('webpack:watch-server', (cb) => {
let started = false;
let serverIgnoreJS = [
'node_modules/*',
'client/*',
'server/staticGenerator.js',
'src/*',
'_public/*',
'gulpfile.babel.js',
'karma.config.js'
];
nodemon({
script: 'server/server.js',
ext: 'js',
exec: 'babel-node',
env: {
NODE_ENV: 'development'
},
ignore: serverIgnoreJS
}).on('start', function() {
if (!started) {
cb();
started = true;
}
});
});
gulp.task('clean-build', () => {
return del(BUILD_PATH);
});
gulp.task('clean-all', ['clean-build'], () => {
return del([
'coverage',
'node_modules'
]);
});
gulp.task('build:static', ['ico', 'data', 'images', 'static-generator']);
gulp.task('build', ['build:static', 'webpack']);
gulp.task('dev', ['build:static', 'webpack:watch-server']);
gulp.task('default', ['build']);