forked from udacity/frontend-nanodegree-arcade-game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
117 lines (102 loc) · 3.03 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
var gulp = require('gulp');
var gulpIf = require('gulp-if');
var autoprefixer = require('gulp-autoprefixer');
var sass = require('gulp-sass');
var useref = require('gulp-useref');
var cssnano = require('gulp-cssnano');
var imagemin = require('gulp-imagemin');
var cache = require('gulp-cache');
var del = require('del');
var runSequence = require('run-sequence');
var browserSync = require('browser-sync');
var uglify = require('gulp-uglify');
var responsive = require('gulp-responsive');
var pug = require('gulp-pug');
gulp.task('watch', ['browserSync', 'compile-pug-to-html', 'compile-scss-to-css'],function(){
gulp.watch('src/views/*.pug', ['compile-pug-to-html']);
gulp.watch('src/*.html', browserSync.reload);
gulp.watch('src/stylesheets/scss/*', ['compile-scss-to-css']);
gulp.watch('src/js/**/*.js', browserSync.reload);
});
gulp.task('browserSync', function(){
browserSync.init({
server: {
baseDir: 'src'
}
})
});
gulp.task('compile-pug-to-html', function buildHTML() {
return gulp.src('src/views/**/*.pug')
.pipe(pug({
pretty: true
}))
.pipe(gulp.dest('src'))
});
gulp.task('compile-scss-to-css', function(){
return gulp.src('src/stylesheets/scss/**/*.scss')
.pipe(sass())
.pipe(gulp.dest('src/stylesheets/css'))
.pipe(browserSync.reload({
stream: true
}));
});
gulp.task('optimize-files', function(){
return gulp.src('src/*.html')
.pipe(useref())
.pipe(gulpIf('*.css', cssnano()))
.pipe(gulpIf('*.js', uglify()))
.pipe(gulp.dest('dist'));
});
gulp.task('copy-images-to-dist', function() {
return gulp.src('src/images/**/*')
.pipe(imagemin({
interlaced: true,
}))
.pipe(gulp.dest('dist/images'))
});
gulp.task('generate-images', function() {
del.sync('src/images/*.png');
return gulp.src('src/images/src/**/*.png')
.pipe(responsive({
'*.png': [{
width: 101,
rename: { suffix: '-large' },
},{
width: 75,
rename: { suffix: '-medium' },
},{
width: 50,
rename: { suffix: '-small' },
}]
}, {
progressive: true,
compressionLevel: 6,
withMetadata: false,
strictMatchImages: false
}))
.pipe(gulp.dest('src/images'))
});
gulp.task('copy-fonts-to-dist', function() {
return gulp.src('src/fonts/**/*')
.pipe(gulp.dest('dist/fonts'))
});
gulp.task('clean', function() {
return del.sync('dist');
});
gulp.task('develop', function(callback) {
runSequence(
['generate-images', 'compile-scss-to-css', 'browserSync'],
'watch',
callback
)
});
gulp.task('build', function(callback) {
runSequence(
'clean',
'compile-pug-to-html',
'generate-images',
'compile-scss-to-css',
['optimize-files', 'copy-images-to-dist', 'copy-fonts-to-dist'],
callback
)
});