-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.babel.js
79 lines (67 loc) · 1.95 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
'use strict';
import gulp from 'gulp';
import webpack from 'webpack-stream';
import path from 'path';
import sync from 'run-sequence';
import nodemon from 'gulp-nodemon';
import beautify from 'gulp-beautify';
import prettify from 'gulp-html-prettify';
let client = 'client';
let server = 'server';
// helper method for resolving client paths
let resolveToClient = (glob) => {
glob = glob || '';
return path.join(client, 'app', glob); // client/app/{glob}
};
// helper method for resolving server paths
let resolveToServer = (glob) => {
glob = glob || '';
return path.join(server, glob); // server/{glob}
};
// map of all paths
let paths = {
clientJS: resolveToClient('**/*.js'), // client js
serverJS: resolveToServer('**/*.js'), // server js
css: resolveToClient('**/*.css'),
html: [
resolveToClient('**/*.html'),
path.join(client, 'index.html')
],
entry: path.join(client, 'app/app.js'),
output: client
};
// use webpack.config.js to build modules
gulp.task('webpack', () => {
return gulp.src(paths.entry)
.pipe(webpack(require('./webpack.config')))
.pipe(gulp.dest(paths.output));
});
gulp.task('watch', () => {
let allPaths = [].concat(paths.clientJS, paths.serverJS, paths.html, paths.css);
gulp.watch(allPaths, ['webpack']);
});
gulp.task('start', function () {
nodemon({
script: './server/server.js'
})
});
gulp.task('beautify-js', function() {
return gulp.src([paths.clientJS, paths.serverJS], {
base: './' // save the original path
})
.pipe(beautify({indent_size: 2}))
.pipe(gulp.dest('./'));
});
gulp.task('prettify-html', function() {
return gulp.src(paths.html, {
base: './' // save the original path
})
.pipe(prettify({indent_size: 2}))
.pipe(gulp.dest('./'));
});
gulp.task('beautify', function() {
sync(['beautify-js', 'prettify-html']);
});
gulp.task('default', (done) => {
sync('webpack', 'start', 'watch', done);
});