-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.js
123 lines (107 loc) · 3.17 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
'use strict';
let gulp = require('gulp'),
swig = require('gulp-swig'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
eslint = require('gulp-eslint'),
uglify = require('gulp-uglify'),
minifycss = require('gulp-minify-css'),
imagemin = require('gulp-imagemin'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
livereload = require('gulp-livereload'),
http = require('http'),
st = require('st');
const vendor = {
scripts: [
'bower_components/vivus/dist/vivus.js',
'bower_components/odometer/odometer.js',
'bower_components/gsap/src/uncompressed/TweenMax.js',
'bower_components/gsap/src/uncompressed/TimelineLite.js',
'bower_components/scrollmagic/scrollmagic/uncompressed/ScrollMagic.js',
'bower_components/scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap.js',
'bower_components/scrollmagic/scrollmagic/uncompressed/plugins/debug.addIndicators.js',
],
styles: [
'bower_components/odometer/themes/odometer-theme-minimal.css',
]
};
// Server - listed on localhost:8080
gulp.task('webserver', function() {
http.createServer(
st({
path: __dirname + '/dist',
index: 'index.html',
cache: false
})
).listen(8080);
});
gulp.task('styles', function() {
return gulp.src(vendor.styles.concat(['sass/styles.scss']))
.pipe(concat('bixos.scss'))
.pipe(sass({ outputStyle: 'expanded' }))
.pipe(autoprefixer())
.pipe(minifycss())
.pipe(rename('bixos.min.css'))
.pipe(gulp.dest('dist/css'))
.pipe(livereload())
.pipe(notify({ message: 'Styles task complete' }));
});
// Lint JS
gulp.task('lint', function () {
return gulp.src(['js/**/*.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
// Concatenate & Minify JS
gulp.task('scripts', ['lint'], function() {
return gulp.src(vendor.scripts.concat(['js/*.js']))
.pipe(concat('bixos.js'))
.pipe(uglify())
.pipe(rename('bixos.min.js'))
.pipe(livereload())
.pipe(gulp.dest('dist/js'));
});
// Images
gulp.task('images', function() {
return gulp.src('img/**/*')
.pipe(imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true,
multipass: true,
svgoPlugins: [
// We have to disable this plugin because it conflicts with Vivus
// TODO: Maybe find a way to only disable it for unicamp.svg?
{mergePaths: false},
],
}))
.pipe(gulp.dest('dist/img'))
.pipe(livereload())
.pipe(notify({ message: 'Images task complete' }));
});
// Templates
gulp.task('templates', function() {
return gulp.src('tpt/index.swig')
.pipe(swig({defaults: {cache: false}}))
.pipe(rename('index.html'))
.pipe(gulp.dest('dist'))
.pipe(livereload())
.pipe(notify({ message: 'Templates task complete' }));
});
// Watch
gulp.task('watch', function() {
// Watch .scss files
gulp.watch('sass/**/*.scss', ['styles']);
// Watch .js files
gulp.watch('js/**/*.js', ['scripts']);
// Watch image files
gulp.watch('img/**/*', ['images']);
// Watch template files
gulp.watch(['tpt/**/*.swig'], ['templates']);
// Create LiveReload server
livereload.listen({ basePath: 'dist' });
});
gulp.task('default', ['webserver', 'styles', 'scripts', 'images', 'templates', 'watch']);