-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
60 lines (48 loc) · 1.51 KB
/
gulpfile.js
File metadata and controls
60 lines (48 loc) · 1.51 KB
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
const gulp = require('gulp');
const gutil = require('gulp-util');
const uglify = require('gulp-uglify');
const liveServer = require('gulp-live-server');
const webpackConfig = require('./webpack.config');
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const stream = require('webpack-stream');
const webpackPort = 9000;
const serverPort = 8000;
const paths = {
HTML: 'index.html',
JS: ['client/**/*.js'],
BUILD: 'build',
SERVER: 'server.js'
};
/*
* MAIN TASKS
*/
gulp.task('default', ['webpack-dev-server', 'server']);
gulp.task('compile', ['webpack']);
gulp.task('server', function() {
const server = liveServer.new('server.js');
server.start();
});
/*
* WEBPACK STUFF
*/
gulp.task('webpack', [], function() {
return gulp.src(paths.JS) // gulp looks for all source files under specified path
.pipe(stream(webpackConfig)) // blend in the webpack config into the source files
.pipe(uglify())
.pipe(gulp.dest(paths.BUILD));
});
gulp.task('webpack-dev-server', function(callback) {
// modify some webpack config options
const config = Object.create(webpackConfig);
config.devtool = 'inline-source-map';
config.debug = true;
// Start a webpack-dev-server which will serve our assets, letting it deal with
// live-reloading for us.
new WebpackDevServer(webpack(config), {
// Tell wepback to pass (proxy) all requests to our server
proxy: {
'*' : `http://localhost:${serverPort}`
}
}).listen(webpackPort, 'localhost');
});