-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
102 lines (88 loc) · 2.43 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
91
92
93
94
95
96
97
98
99
100
101
102
import gulp from 'gulp'
import del from 'del'
import browserify from 'browserify'
import babelify from 'babelify'
import source from 'vinyl-source-stream'
import buffer from 'vinyl-buffer'
import gulpIf from 'gulp-if'
import uglify from 'gulp-uglify'
import minifyHTML from 'gulp-minify-html'
import minifyCSS from 'gulp-minify-css'
import concat from 'gulp-concat'
import mustache from 'gulp-mustache'
import Customize from './customize'
var paths = {
html: [
'src/index.html'
],
scripts: [
'src/scripts/main.jsx'
],
styles: [
'node_modules/normalize.css/normalize.css',
'src/styles/app.css'
],
images: [
]
}
if (Customize.competitionLogo && Customize.competitionLogo.src) {
paths.images.push(Customize.competitionLogo.src)
}
if (Customize.competitionNotifyLogo && Customize.competitionNotifyLogo.src) {
paths.images.push(Customize.competitionNotifyLogo.src)
}
if (Customize.extraImages) {
Array.prototype.push.apply(paths.images, Customize.extraImages)
}
function isProduction () {
return process.env['NODE_ENV'] === 'production'
}
gulp.task('clean_html', function () {
return del(['build/html/*.html'])
})
gulp.task('html', gulp.series('clean_html', function () {
return gulp.src(paths.html)
.pipe(mustache({title: Customize.competitionTitle}))
.pipe(gulpIf(isProduction, minifyHTML()))
.pipe(gulp.dest('build/html'))
}))
gulp.task('clean_scripts', function () {
return del(['build/assets/js/*.js'])
})
gulp.task('scripts', gulp.series('clean_scripts', function () {
return browserify({
entries: paths.scripts,
extensions: ['.jsx'],
debug: !isProduction()
})
.transform(babelify)
.bundle()
.pipe(source('app.js'))
.pipe(buffer())
.pipe(gulpIf(isProduction, uglify()))
.pipe(gulp.dest('build/assets/js'))
}))
gulp.task('clean_styles', function () {
return del(['build/assets/css/*.css'])
})
gulp.task('styles', gulp.series('clean_styles', function () {
return gulp.src(paths.styles)
.pipe(concat('app.css'))
.pipe(gulpIf(isProduction, minifyCSS()))
.pipe(gulp.dest('build/assets/css'))
}))
gulp.task('clean_images', function () {
return del(['build/assets/images/*'])
})
gulp.task('images', gulp.series('clean_images', function (done) {
if (paths.images.length === 0) {
done()
return
}
return gulp
.src(paths.images)
.pipe(gulp.dest('build/assets/images'))
}))
gulp.task('default', gulp.series('html', 'scripts', 'styles', 'images', function (done) {
done()
}))