-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
100 lines (82 loc) · 2.75 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
'use strict';
const gulp = require('gulp');
const watch = require('gulp-watch');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const cssBase64 = require('gulp-css-base64');
const path = require('path');
const notify = require('gulp-notify');
const browserSync = require('browser-sync');
const imagemin = require('gulp-imagemin');
const del = require('del');
const cache = require('gulp-cache');
const uglify = require('gulp-uglify');
const autoprefixer = require('gulp-autoprefixer');
const runSequence = require('run-sequence');
const htmlmin = require('gulp-htmlmin');
const merge = require('merge-stream');
gulp.task('sass', function () {
return gulp.src('./src/scss/styles.scss')
.pipe(sourcemaps.init())
.pipe(sass({
errLogToConsole: false,
paths: [ path.join(__dirname, 'scss', 'includes') ]
})
.on("error", notify.onError(function(error) {
return "Failed to Compile SCSS: " + error.message;
})))
.pipe(cssBase64())
.pipe(autoprefixer())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./src/css/'))
.pipe(gulp.dest('./dist/css/'))
.pipe(browserSync.reload({
stream: true
}))
.pipe(notify("SCSS Compiled Successfully :)"));
});
gulp.task('jsmin', function() {
return gulp.src(['./src/js/**/*.js'])
.pipe(uglify())
.pipe(gulp.dest('./dist/js/'));
});
gulp.task('htmlmin', function() {
var indexOutput = gulp.src('./src/index.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('./dist/'));
var partialsOutput = gulp.src('./src/partials/*.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('./dist/partials/'));
return merge(indexOutput, partialsOutput);
});
gulp.task('imagemin', function (){
return gulp.src('./src/img/**/*.+(png|jpg|jpeg|gif|svg)')
.pipe(cache(imagemin({
interlaced: true
})))
.pipe(gulp.dest('./dist/img'));
});
gulp.task('browserSync', function() {
browserSync({
server: {
baseDir: './src/'
}
})
});
gulp.task('yarn', function() {
var graphOutput = gulp.src('./src/js/vendor/**/*')
.pipe(gulp.dest('./dist/js/vendor'));
return merge(graphOutput);
});
gulp.task('watch', ['browserSync'], function () {
gulp.watch('./src/scss/**/*', ['sass']);
gulp.watch('./src/**/*.js').on('change', browserSync.reload);
gulp.watch('./src/**/*.html').on('change', browserSync.reload);
});
gulp.task('clean', function() {
del('dist');
});
gulp.task('default', ['sass', 'watch']);
gulp.task('build', function() {
runSequence('clean', 'sass', 'imagemin', 'htmlmin', 'jsmin', 'yarn');
});