-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
76 lines (60 loc) · 1.64 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
'use strict';
const gulp = require('gulp');
const del = require('del');
const webpack = require('webpack');
const nodemon = require('gulp-nodemon');
const buildDest = 'dist/';
const webpackConfigLocations = {
'dev': './webpack.config.dev',
'prod': './webpack.config.prod'
};
let webpackConfig = webpackConfigLocations.prod;
gulp.task('clean', function (done) {
del(buildDest).then(function () {
done();
});
});
gulp.task('build:webpack', function (done) {
webpack(require(webpackConfig)).run((err, stats) => {
if (err) {
console.log(err, stats);
throw err;
}
if (stats.hasErrors()) {
throw new Error(stats.toString("errors-only"));
}
done();
});
});
gulp.task('build:html', function () {
return gulp.src('src/**/*.html')
.pipe(gulp.dest(buildDest));
});
gulp.task('build:favicon', function () {
return gulp.src('src/client/favicon/*')
.pipe(gulp.dest(buildDest + 'client/assets'));
});
gulp.task('build', gulp.parallel(['build:webpack', 'build:html', 'build:favicon']));
gulp.task('set:dev', function (done) {
webpackConfig = webpackConfigLocations.dev;
done();
});
gulp.task('build:dev', gulp.series(['set:dev', 'build']));
const buildAndStartDevServer = gulp.series([
'build:dev',
function (done) {
nodemon({
script: buildDest + 'server/server.bundle.js',
watch: buildDest + 'server',
ext: 'js',
env: {
'PORT': '5000',
'DATABASE_URL': 'postgres://localhost/postgres'
}
});
gulp.watch('src/**/*', gulp.series(['build']));
done();
}
]);
gulp.task('serve', buildAndStartDevServer);
gulp.task('default', buildAndStartDevServer);