-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
93 lines (75 loc) · 2.53 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
var WEBPACK_PORT_NUMBER = 8000,
gulp = require('gulp'),
gutil = require('gulp-util'),
webpack = require('webpack'),
WebpackDevServer = require('webpack-dev-server'),
webpackConfig = require('./webpack.config.js'),
del = require('del'),
webpackServerInstance = null;
// Build task for prod
gulp.task('default', ['build']);
gulp.task('build', ['copy-static'], function(callback) {
var config = Object.create(webpackConfig);
config.plugins = config.plugins.concat(
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
'minimize': true
})
);
webpack(config, function(err, stats) {
if(err) {
throw new gutil.PluginError('webpack:build', err);
}
gutil.log('[build]', stats.toString({'colors': true}));
callback();
});
});
// Build task for dev
gulp.task('build-dev', ['copy-static'], function(callback) {
var config = Object.create(webpackConfig);
config.debug = true;
config.devtool = 'source-map';
webpack(config, function(err, stats) {
if(err) {
throw new gutil.PluginError('webpack:build-dev', err);
}
gutil.log('[build-dev]', stats.toString({'colors': true}));
callback();
});
});
// Watch task for dev
gulp.task('watch-dev', ['build-dev'], function() {
gulp.watch(['src/assets/**/*'], ['build-dev']);
});
// Run dev server
gulp.task('run', ['copy-static'], function(callback) {
var config = Object.create(webpackConfig);
config.debug = true;
config.devtool = 'eval';
webpackServerInstance = new WebpackDevServer(webpack(config), {
'publicPath' : '/',
'contentBase': config.output.path,
'stats': {
'colors': true
}
}
);
// Start a webpack-dev-server
webpackServerInstance.listen(WEBPACK_PORT_NUMBER, "localhost", function(err) {
if(err) {
throw new gutil.PluginError('webpack:dev-server', err);
}
gutil.log('[run]', 'Dynamic reload: http://localhost:' + WEBPACK_PORT_NUMBER + '/webpack-dev-server/index.html');
gutil.log('[run]', 'Static version: http://localhost:' + WEBPACK_PORT_NUMBER + '/index.html');
callback();
}
);
});
// Copy static data like images
gulp.task('copy-static', function() {
gulp.src(['src/assets/images/**/*']).pipe(gulp.dest('build/webpack/images'));
});
// Clean task
gulp.task('clean', function(done) {
del(['build'], done);
});