-
Notifications
You must be signed in to change notification settings - Fork 62
/
gulpfile.js
98 lines (80 loc) · 2.05 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
94
95
96
97
98
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
gulp.task('lint', function () {
return gulp.src([
'src/**/*.js'
])
.pipe($.eslint())
.pipe($.eslint.format())
.pipe($.eslint.failOnError());
});
gulp.task('html', function() {
return gulp.src('./src/index.html')
.pipe($.useref())
.pipe(gulp.dest('./dist'))
.pipe($.size());
});
gulp.task('clean', require('del').bind(null, ['dist', '.publish']));
gulp.task('server', function(cb) {
var httpServer = require('http-server');
httpServer.createServer({
root: './src/',
cors: true
}).listen(8080, cb);
});
var webpackSettings = {
stats: {
colors: true,
reasons: false,
errorDetails: true,
hash: false,
version: false,
timings: true,
chunkModules: false,
modules: true,
cached: false,
source: true
}
};
function webpackTask(cb) {
var started = false;
var config = require('./webpack.config')(true);
var bundler = require('webpack')(config);
function bundle(err, stats) {
if (err) {
throw new $.util.PluginError('webpack', err);
}
$.util.log('[webpack]', stats.toString(webpackSettings.stats));
if (!started) {
started = true;
return cb();
}
}
bundler.run(bundle);
}
gulp.task('webpack', webpackTask);
gulp.task('webpack-dev-server', function(cb) {
var WebpackDevServer = require('webpack-dev-server');
var webpack = require('webpack');
var compiler = webpack(require('./webpack.config')(false));
new WebpackDevServer(compiler, {
contentBase: './src',
hot: true,
quiet: false,
noInfo: false,
lazy: false,
watchDelay: 300,
stats: webpackSettings.stats
}).listen(8080, '0.0.0.0', cb);
});
gulp.task('watch', ['webpack-dev-server']);
gulp.task('build', ['lint', 'html', 'webpack'], function() {
return gulp.src('dist/**/*').pipe($.size({title: 'build', gzip: true}));
});
gulp.task('default', ['clean'], function() {
gulp.start('build');
});
gulp.task('deploy', function() {
return gulp.src('./dist/**/*')
.pipe($.ghPages());
});