-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
81 lines (66 loc) · 1.94 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
var childProcess = require('child_process');
var del = require('del');
var gulp = require('gulp');
var concat = require('gulp-concat');
var connect = require('gulp-connect');
var sourcemaps = require('gulp-sourcemaps');
var cleanCSS = require('gulp-clean-css');
var minifyHTML = require('gulp-minify-html');
var ejs = require('gulp-ejs');
var rename = require('gulp-rename');
var replace = require('gulp-replace');
var uglify = require('gulp-uglify');
gulp.task('dist-clean', function() {
return del(['dist']);
});
gulp.task('dist-copy', function() {
return gulp
.src(['src/favicon.ico', 'src/img/**', 'src/pdf/**'], {base: 'src'})
.pipe(gulp.dest('dist'))
});
var commitHash;
gulp.task('commit-hash', function(cb) {
childProcess.exec('git rev-parse HEAD', function(error, stdout, stderr) {
commitHash = stdout.trim();
cb();
});
});
gulp.task('dist-ejs', gulp.series('commit-hash', function() {
return gulp
.src('src/ejs/**/*.ejs')
.pipe(ejs())
.pipe(replace('__GIT_COMMIT_HASH__', commitHash))
.pipe(minifyHTML({}))
.pipe(rename({extname: '.html'}))
.pipe(gulp.dest('dist'))
}));
gulp.task('dist-js', function() {
return gulp
.src('src/js/*.js')
.pipe(sourcemaps.init())
.pipe(concat('bundle.min.js'))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist/js'))
});
gulp.task('dist-css', function() {
return gulp
.src('src/css/*.css')
.pipe(sourcemaps.init())
.pipe(concat('bundle.min.css'))
.pipe(cleanCSS())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist/css'))
});
gulp.task('dist', gulp.series('dist-copy', 'dist-ejs', 'dist-js', 'dist-css'));
gulp.task('watch', function() {
var watch = ['src/**'];
return gulp.watch(watch, gulp.series('dist'));
});
gulp.task('connect', gulp.series('dist', function() {
return connect.server({
root: 'dist',
});
}));
gulp.task('start', gulp.parallel('watch', 'connect'));
gulp.task('default', gulp.series('dist'));