-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
114 lines (98 loc) · 3.32 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
// Load plugins
let gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
rename = require('gulp-rename'),
clean = require('gulp-clean'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
cache = require('gulp-cache'),
livereload = require('gulp-livereload'),
connect = require('gulp-connect'),
nunjucksRender = require('gulp-nunjucks-render'),
bb = require('bitballoon');
// Styles
gulp.task('styles', function() {
return sass('styles/app.scss', {'loadPath' : './'})
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(gulp.dest('dist/styles'))
.pipe(rename({ suffix: '.min' }))
.pipe(minifycss())
.pipe(gulp.dest('dist/styles'))
.pipe(notify({ message: 'Styles task complete' }));
});
// Scripts
gulp.task('scripts', function() {
return gulp.src('{js/global,lib}/*.js')
.pipe(concat('main.js'))
.pipe(gulp.dest('dist/scripts'))
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(gulp.dest('dist/scripts'))
.pipe(notify({ message: 'Scripts task complete' }));
});
gulp.task('page_scripts', function() {
return gulp.src('js/pages/*.js')
.pipe(gulp.dest('dist/scripts'))
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(gulp.dest('dist/scripts'))
.pipe(notify({ message: 'Page scripts task complete' }));
});
// Images
gulp.task('images', function() {
return gulp.src('img/**/*')
.pipe(cache(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })))
.pipe(gulp.dest('dist/images'))
.pipe(notify({ message: 'Images task complete' }));
});
// Clean
gulp.task('clean', function() {
return gulp.src(['dist/styles', 'dist/scripts', 'dist/images'], {read: false})
.pipe(clean());
});
// Default task
gulp.task('default', ['clean'], function() {
gulp.start('styles', 'scripts', 'page_scripts', 'images', 'html');
});
gulp.task('html', function() {
// return [gulp.src('index.html')
// .pipe(gulp.dest('dist/'))
// .pipe(notify({message: 'HTML task complete'})),
// gulp.src('pages/**/*.html')
// .pipe(gulp.dest('dist/pages/')),
// gulp.src('fonts/**/*')
// .pipe(gulp.dest('dist/fonts/'))];
return [gulp.src('./pages/**/*.+(html|nunjucks)')
.pipe(nunjucksRender({path: ['./pages/partials']}))
.pipe(gulp.dest('dist/')),
gulp.src('fonts/**/*')
.pipe(gulp.dest('dist/fonts/')),
gulp.src('static/**/*')
.pipe(gulp.dest('dist/static/'))
]
});
// Watch
gulp.task('watch', function() {
// Watch .scss files
gulp.watch('styles/**/*.scss', ['styles']);
// Watch .js files
gulp.watch('js/**/*.js', ['scripts', 'page_scripts']);
// Watch image files
gulp.watch('img/**/*', ['images']);
// Watch html files
gulp.watch('pages/**/*.+(html|nunjucks)', ['html']);
// Watch any files in dist/, reload on change
gulp.watch(['dist/**']).on('change', function(file) {
gulp.src(file.path)
.pipe(connect.reload())
});
});
gulp.task('serve', ['default'], function() {
connect.server({root: 'dist', livereload: true})
gulp.start('watch')
});