-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.babel.js
90 lines (76 loc) · 2.12 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
import path from 'path';
import gulp from 'gulp';
import gulpLoadPlugins from 'gulp-load-plugins';
import del from 'del';
import runSequence from 'run-sequence';
import webpack from 'webpack';
import minimist from 'minimist';
import revReplace from 'gulp-rev-replace';
const $ = gulpLoadPlugins();
const argv = minimist(process.argv.slice(2));
const src = Object.create(null);
// Clean output directory
gulp.task('clean', cb => {
del(['build'], cb);
});
// Static files
gulp.task('assets', () => {
src.assets = ['src/public/**', '!src/public/assets/images/**/*'];
gulp.src(src.assets)
.pipe($.changed('build'))
.pipe(gulp.dest('build'))
.pipe($.size({title: 'assets'}));
});
gulp.task('webpack', cb => {
const config = require('./webpack.config.js');
const verbose = !!argv.verbose;
// run webpack
webpack(config, (err, stats) => {
if(err) {
throw new gutil.PluginError('webpack', err);
}
console.log(stats.toString({
colors: $.util.colors.supportsColor,
hash: verbose,
version: verbose,
timings: verbose,
chunks: verbose,
chunkModules: verbose,
cached: verbose,
cachedAssets: verbose
}));
cb();
});
});
gulp.task('revision', cb => {
return gulp.src(['build/assets/**/*.js'])
.pipe($.rev())
.pipe(gulp.dest('build/assets'))
.pipe($.rev.manifest())
.pipe(gulp.dest('build'));
});
gulp.task('revreplace', ['revision'], cb => {
let manifest = gulp.src('build/rev-manifest.json');
return gulp.src('build/index.html')
.pipe(revReplace({manifest: manifest}))
.pipe(gulp.dest('build'));
});
gulp.task('minify-html', cb => {
return gulp.src('build/index.html')
.pipe($.minifyHtml())
.pipe(gulp.dest('build'));
});
// Optimize images
gulp.task('images', () =>
gulp.src('src/public/assets/images/**/*')
.pipe($.imagemin({
progressive: true,
interlaced: true
}))
.pipe(gulp.dest('build/assets/images'))
.pipe($.size({title: 'images'}))
);
// Build the app from source code
gulp.task('build', ['clean'], cb => {
runSequence(['assets', 'webpack', 'images'], ['revreplace'], ['minify-html'], cb);
});