-
Notifications
You must be signed in to change notification settings - Fork 26
/
gulpfile.js
124 lines (110 loc) · 3.1 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
'use strtict'
var gulp = require('gulp')
var browserSync = require('browser-sync').create()
var reload = browserSync.reload
var concat = require('gulp-concat')
var minify = require('gulp-minify')
var cleanCss = require('gulp-clean-css')
var rename = require('gulp-rename')
var htmlmin = require('gulp-htmlmin')
var del = require('del')
var uncss = require('gulp-uncss')
var uglify = require('gulp-uglify')
var pump = require('pump')
// Default Gulp task to run including all necessary dependencies
gulp.task('default', ['browser-sync', 'build'], function () {
gulp.watch(['source/**/*.html', 'source/js/*.js',
'source/css/*.css'
], ['build'])
gulp.watch(['public/**/*.html', 'public/js/*.js',
'public/css/*.css'
], reload)
})
gulp.task('browser-sync', function () {
browserSync.init({
server: './public'
})
})
// Build task to initiate minify tasks for CSS and JS
gulp.task('build', ['minify-html', 'pack-minify-js', 'pack-minify-css', 'pack-minify-sponsor-css', 'gulp-uncss',
'copy-sponsor', 'copy-img', 'copy-css'
])
// Task to minify HTML
gulp.task('minify-html', function () {
return gulp.src('source/*.html')
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(gulp.dest('public/'))
})
// Task to uglify JS
gulp.task('pack-minify-js', function (cb) {
pump([
gulp.src(['source/js/*.js', '!source/js/*.min.js'])
.pipe(minify({
ext: {
min: '.min.js'
},
noSource: true
})),
uglify(),
gulp.dest('./public/js')
],
cb
)
})
// Task to minify CSS
gulp.task('pack-minify-css', function () {
return gulp.src(['source/css/*.css', '!source/css/*.min.css'])
.pipe(concat('main.css'))
.pipe(cleanCss())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('public/css'))
})
// Task to minify sponsor CSS
gulp.task('pack-minify-sponsor-css', function () {
return gulp.src(['source/css/*.css', '!source/css/*.min.css'])
.pipe(concat('sponsor.css'))
.pipe(cleanCss())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('public/css'))
})
// Task to minify campus CSS
// gulp.task('pack-minify-campus-css', function () {
// return gulp.src(['source/css/campus.css', '!source/css/*.min.css'])
// .pipe(concat('sponsor.css'))
// .pipe(cleanCss())
// .pipe(rename({
// suffix: '.min'
// }))
// .pipe(gulp.dest('public/css'))
// })
// Task to remove unused css
gulp.task('gulp-uncss', function () {
return gulp.src('./css/bootstrap-custom.css')
.pipe(uncss({
html: ['index.html'],
ignore: [/\modal/]
}))
.pipe(gulp.dest('public/css'))
})
// // Task to copy assets
gulp.task('copy-sponsor', function () {
return gulp.src('source/**/*.html')
.pipe(gulp.dest('public/'))
})
// // Task to copy assets
gulp.task('copy-img', function () {
return gulp.src('source/assets/img/*')
.pipe(gulp.dest('public/assets/img'))
})
gulp.task('copy-css', function () {
return gulp.src('source/css/*.min.css')
.pipe(gulp.dest('public/css'))
})
// Task to delete target assets folder for recreation
gulp.task('clean', function () {
return del(['public/**', '!public'])
})