-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.babel.js
109 lines (87 loc) · 2.83 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
107
108
109
import gulp from 'gulp'
import gutil from 'gulp-util'
import cleanCSS from 'gulp-clean-css';
import imagemin from 'gulp-imagemin';
import del from 'del';
import sass from 'gulp-sass';
import webpack from 'webpack'
import nodemon from 'gulp-nodemon';
import browserSync from 'browser-sync';
const CLIENT = {
SRC: 'client',
DEST: 'build/client'
};
const SERVER = {
SRC: 'server',
DEST: 'build/server'
};
gulp.task('clean', () => {
return del.sync([CLIENT.DEST, SERVER.DEST]);
});
gulp.task('copy', () => {
const vendors = {
'phaser': 'node_modules/phaser-ce/build/*.min.js',
'socket.io': 'node_modules/socket.io-client/dist/*.slim.js'
};
for (let name in vendors) {
gulp.src(vendors[name])
.pipe(gulp.dest('build/client/vendor/' + name));
}
});
gulp.task('webpack-server', (callback) => {
webpack(require('./webpack.server.config.js'), (err, stats) => {
if (err) throw new gutil.PluginError('webpack', err);
callback();
});
});
gulp.task('webpack-client', (callback) => {
webpack(require('./webpack.client.config.js'), (err, stats) => {
if (err) throw new gutil.PluginError('webpack', err);
callback();
});
});
gulp.task('sass', () => {
return gulp.src(CLIENT.SRC + '/sass/main.scss')
.pipe(sass().on('error', sass.logError))
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(gulp.dest(CLIENT.DEST));
});
gulp.task('images', () => {
return gulp.src(CLIENT.SRC + '/images/*')
.pipe(imagemin())
.pipe(gulp.dest(CLIENT.DEST + '/images'));
});
gulp.task('build', ['clean', 'copy', 'webpack-server', 'webpack-client', 'sass', 'images'], () => {});
gulp.task('watch', ['build'], () => {
let watcher = {
client: gulp.watch(CLIENT.SRC + '/js/**/*.js', ['webpack-client']),
server: gulp.watch(SERVER.SRC + '/**/*.js', ['webpack-server']),
sass: gulp.watch(CLIENT.SRC + '/sass/**/*.scss', ['sass']),
html: gulp.watch(CLIENT.SRC + '/*.html', ['webpack-client']),
images: gulp.watch(CLIENT.SRC + '/images/*', ['images'])
};
let notify = (event) => {
gutil.log('File', gutil.colors.yellow(event.path), 'was', gutil.colors.magenta(event.type));
};
for (let key in watcher) {
watcher[key].on('change', notify);
}
gutil.log('Waiting for file changes...');
});
gulp.task('start-servers', ['watch'], () => {
return nodemon({
script: SERVER.DEST + '/main.js',
watch: SERVER.DEST
});
});
gulp.task('browser-sync', ['start-servers'], () => {
browserSync.init(null, {
proxy: 'http://localhost:8080',
files: ['build/client/**/*.*'],
port: 7000,
browser: 'google chrome'
});
});
gulp.task('default', ['browser-sync'], () => {
gutil.log('Web server and game server is running.');
});