-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
107 lines (94 loc) · 2.6 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
/*
* Gulpfile
*/
// Load plugins
const gulp = require('gulp');
const pug = require('gulp-pug');
const stylus = require('gulp-stylus');
const autoprefixer = require('gulp-autoprefixer');
const cleanCSS = require('gulp-clean-css');
const uglify = require('gulp-uglify');
const imagemin = require('gulp-imagemin');
const rename = require('gulp-rename');
const browserSync = require('browser-sync');
// Variables
var reload = browserSync.reload;
// Paths
var srcPath = 'src';
var distPath = 'dist';
var paths = {
templates: srcPath + '/templates',
styles: srcPath + '/styles',
scripts: srcPath + '/scripts',
images: srcPath + '/images',
fonts: srcPath + '/fonts'
};
// Templates
gulp.task('templates', function() {
return gulp.src(paths.templates + '/*.pug')
.pipe(pug({
pretty: true
}))
.pipe(gulp.dest(distPath));
});
// Styles
gulp.task('styles', function() {
return gulp.src(paths.styles + '/*.styl')
.pipe(stylus())
.on('error', swallowError)
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(cleanCSS())
.on('error', swallowError)
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(distPath + '/assets/css'))
.pipe(reload({stream: true}));
});
// Scripts
gulp.task('scripts', function() {
return gulp.src(paths.scripts + '/**/*.js')
.pipe(uglify())
.on('error', swallowError)
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(distPath + '/assets/js'))
.on('end', reload);
});
// Images
gulp.task('images', function() {
return gulp.src(paths.images + '/**/*')
.pipe(imagemin())
.on('error', swallowError)
.pipe(gulp.dest(distPath + '/assets/images'))
.on('end', reload);
});
// Fonts
gulp.task('fonts', function() {
return gulp.src(paths.fonts + '/**/*')
.pipe(gulp.dest(distPath + '/assets/fonts'))
.on('end', reload);
});
// Watch
gulp.task('templates-watch', ['templates'], reload);
// Prevent errors from breaking gulp watch
function swallowError (error) {
console.log(error.toString());
this.emit('end');
}
// Build: one shot
gulp.task('build', ['templates', 'styles', 'scripts', 'images', 'fonts']);
// Default: watch changes
gulp.task('default', ['build'], function() {
browserSync.init({
server: {
baseDir: './dist'
},
notify: false
});
gulp.watch(paths.templates + '/**/*.pug', ['templates-watch']);
gulp.watch(paths.styles + '/**/*.styl', ['styles']);
gulp.watch(paths.scripts + '/**/*.js', ['scripts']);
gulp.watch(paths.images + '/**/*', ['images']);
gulp.watch(paths.fonts + '/**/*', ['fonts']);
});