forked from fortruce/react-fullstack-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
79 lines (67 loc) · 2.03 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
import gulp from 'gulp';
import webpack from 'webpack';
import WebpackHotMiddleware from 'webpack-hot-middleware';
import WebpackDevMiddleware from 'webpack-dev-middleware';
import express from 'express';
import nodemon from 'nodemon';
import path from 'path';
import request from 'request';
import configs from './webpack.config';
const [ frontendConfig, backendConfig ] = configs;
gulp.task('dev', () => {
const compiler = webpack(frontendConfig);
// const server = new WebpackDevServer(compiler, {
// contentBase: path.join(__dirname, 'build', 'public'),
// historyApiFallback: true,
// hot: true,
// proxy: {
// '*': 'http://localhost:8080'
// }
// });
const server = express();
// proxy requests to api
server.use('/api*', (req, res) => {
request({
// use req.originalUrl instead of req.path since mount point is removed
// from req.path (ie: '/api*' will be removed from req.path)
url: 'http://localhost:8080' + req.originalUrl,
qs: req.query,
method: req.method.toUpperCase()
}).pipe(res);
});
var webpackDevMiddleware = WebpackDevMiddleware(compiler);
server.use(webpackDevMiddleware);
server.use(WebpackHotMiddleware(compiler));
server.get('*', function(req, res) {
req.url = '/';
webpackDevMiddleware(req, res, ()=>{});
});
server.listen(3000, 'localhost', (err) => {
if (err)
return console.log(err);
console.log('webpack-dev-server listening on localhost:3000');
});
});
gulp.task('backend-watch', () => {
webpack(backendConfig).watch(100, (err) => {
if (err)
return console.log(err);
nodemon.restart();
});
});
gulp.task('server', ['backend-watch'], () => {
nodemon({
execMap: {
js: 'node'
},
script: path.join(__dirname, 'build', 'server.js'),
// do not watch any directory/files to refresh
// all refreshes should be manual
watch: ['foo/'],
ext: 'noop',
ignore: ['*']
}).on('restart', () => {
console.log('nodemon: restart');
});
});
gulp.task('default', ['dev', 'server']);