-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
125 lines (98 loc) · 4.02 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
125
'use strict'
// packages
const autoprefixer = require( 'gulp-autoprefixer' )
const clean = require( 'gulp-clean' )
const concat = require( 'gulp-concat' )
const cssnano = require( 'gulp-cssnano' )
const file = require( 'gulp-file' )
const fs = require( 'fs' )
const gulp = require( 'gulp' )
const notify = require( 'gulp-notify' )
const plumber = require( 'gulp-plumber' )
const rename = require( 'gulp-rename' )
const runSequence = require( 'run-sequence' )
const sass = require( 'gulp-sass' )
const uglify = require( 'gulp-uglify' )
const sitemap = require( 'gulp-sitemap' )
const imageResize = require( 'gulp-image-resize' )
const imageMin = require( 'gulp-imagemin' )
// custom variables
const srcFolder = 'src/'
const dstFolder = 'dist/'
const img_srcFolder = srcFolder + 'images/'
const style_srcFolder = srcFolder + 'styles/'
const scripts_srcFolder = srcFolder + 'scripts/'
const photos_srcFolder = srcFolder + 'team-photos/'
// Error / Success Handling
let onError = function(err) {
notify.onError({
title: "Error: " + err.plugin,
subtitle: "<%= file.relative %>",
message: "<%= error.message %>",
sound: "Beep",
icon: "logo/logo.png",
})( err )
console.log( err.toString() )
this.emit( 'end' )
}
function onSuccess(msg) {
return {
message: msg + " Complete! ",
icon: "logo/logo.png",
onLast: true
}
}
function notifyFunc(msg) {
return gulp.src( '.', { read: false } )
.pipe( notify( onSuccess( msg ) ) )
}
// Copy
gulp.task('copy', function() {
gulp.src( img_srcFolder + '**/*/' )
.pipe(gulp.dest( dstFolder + 'images/' ))
gulp.src( srcFolder + '**/*.html' )
.pipe(gulp.dest( dstFolder ))
return gulp.src( srcFolder + 'styleguide.html' )
.pipe(gulp.dest( dstFolder ))
.pipe(notify(onSuccess( 'Copy' )))
})
// Compress team photos
gulp.task('compress_photos', function() {
gulp.src(photos_srcFolder + '*')
.pipe(imageResize({
width: 500,
height: 500,
upscale: false,
crop: true
}))
.pipe(imageMin())
.pipe(gulp.dest(dstFolder + 'images/team-photos/'))
.pipe(notify(onSuccess('Compressed photos')))
})
// styles: Compile and Minify style / CSS Files
const style_srcFile = 'master.scss'
const style_destFile = 'master.min.css'
gulp.task('styles', function() {
return gulp.src( style_srcFolder + style_srcFile )
.pipe( plumber({ errorHandler: onError }) )
.pipe( sass( ) )
.pipe( autoprefixer({ browsers: ['last 4 versions', 'iOS > 7'], remove: false }) )
.pipe( cssnano({ autoprefixer: false, safe: true }) )
.pipe( rename( style_destFile ) )
.pipe( gulp.dest( dstFolder ) )
})
// Rebuild JS
const scripts_destFile = 'master.min.js'
gulp.task( 'scripts', function() {
return gulp.src( scripts_srcFolder + '**/*.js' )
.pipe( plumber({ errorHandler: onError }))
.pipe( concat( scripts_destFile ) )
.pipe( uglify( ) )
.pipe( gulp.dest( dstFolder ) )
})
gulp.task( 'watch_js', function() { gulp.watch(scripts_srcFolder + '**/*.js', ['scripts']) })
gulp.task( 'watch_styles', function() { gulp.watch(style_srcFolder + '**/*.scss', ['styles']) })
gulp.task( 'watch_content', function() { gulp.watch(srcFolder + '**/*.html', ['copy']) })
gulp.task( 'watch', ['watch_js', 'watch_styles', 'watch_content'] )
gulp.task( 'build', ['scripts', 'styles', 'copy', 'compress_photos'] )
gulp.task( 'default', ['build', 'watch'] )