-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
121 lines (106 loc) · 2.83 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
var gulp = require('gulp');
var del = require('del');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var cleanCSS = require('gulp-clean-css');
var changed = require('gulp-changed');
var htmlmin = require('gulp-htmlmin');
var connect = require('gulp-connect');
var watch = require('gulp-watch');
var ngrok = require('ngrok');
function onError(error) {
console.log(error);
this.emit('end');
}
gulp.task('clean', function() {
return del([
'dist/**/*'
]);
});
gulp.task('sass', function() {
return gulp.src('src/sass/main.scss')
.pipe(changed('dist/css/'))
.pipe(sourcemaps.init())
.pipe(sass())
.on('error', onError)
.pipe(autoprefixer())
.pipe(cleanCSS())
.pipe(sourcemaps.write('./maps'))
.pipe(connect.reload())
.pipe(gulp.dest('dist/css/'))
});
gulp.task('sass-gallery', function() {
return gulp.src('src/sass-gallery/main-gallery.scss')
.pipe(changed('dist/css/'))
.pipe(sourcemaps.init())
.pipe(sass())
.on('error', onError)
.pipe(autoprefixer())
.pipe(cleanCSS())
.pipe(sourcemaps.write('./maps'))
.pipe(connect.reload())
.pipe(gulp.dest('dist/css/'))
});
gulp.task('js', function() {
return gulp.src('src/js/**/*.js')
.pipe(changed('dist/js/'))
.pipe(uglify())
.on('error', onError)
.pipe(connect.reload())
.pipe(gulp.dest('dist/js/'))
})
gulp.task('css', function() {
return gulp.src('src/css/**/*')
.pipe(gulp.dest('dist/css/'))
})
gulp.task('html', function() {
return gulp.src('src/*.html')
.pipe(changed('dist/'))
.pipe(htmlmin({
collapseWhitespace: true
}))
.on('error', onError)
.pipe(connect.reload())
.pipe(gulp.dest('dist/'));
});
gulp.task('img', function() {
return gulp.src(['src/img/**/*.+(png|jpg|svg)', '!src/img/**/originals/**'])
.pipe(changed('dist/img/'))
.pipe(imagemin({
verbose: true
}))
.pipe(gulp.dest('dist/img/'))
})
gulp.task('extras', function() {
return gulp.src(['src/favicon.ico', 'CNAME'])
.pipe(gulp.dest('dist/'))
})
gulp.task('fonts', function() {
return gulp.src('src/fonts/**/*')
.pipe(gulp.dest('dist/fonts/'))
})
gulp.task('connect', function() {
connect.server({
livereload: true,
root: 'dist'
});
/*ngrok.connect(8080, function(err, url) {
console.log(err, url);
});*/
});
gulp.task('watch', function() {
gulp.watch('src/sass/**/*.scss', ['sass']);
gulp.watch('src/sass-gallery/**/*.scss', ['sass-gallery']);
gulp.watch('src/img/**', ['img']);
gulp.watch('src/js/**', ['js']);
gulp.watch('src/*.html', ['html']);
});
gulp.task('webserver', ['watch', 'connect'], function() {
console.log('Starting dev server...');
});
gulp.task('default', ['sass', 'sass-gallery', 'html', 'img', 'js', 'css', 'extras', 'fonts'], function() {
console.log('Building dist folder...');
});