-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
134 lines (106 loc) · 3.2 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
122
123
124
125
126
127
128
129
130
131
132
133
134
'use strict';
// https://css-tricks.com/gulp-for-beginners/
// Documentation
// https://browsersync.io/docs/gulp
// https://browsersync.io/docs/options
// https://www.npmjs.com/package/gulp-sass
// https://www.npmjs.com/package/gulp-sourcemaps
// https://www.npmjs.com/package/gulp-autoprefixer
// https://www.npmjs.com/package/gulp-uglify
// https://github.com/robrich/gulp-if
// https://www.npmjs.com/package/gulp-cssnano
// var runSequence = require('run-sequence');
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var useref = require('gulp-useref');
var uglify = require('gulp-uglify');
var gulpIf = require('gulp-if');
var cssnano = require('gulp-cssnano');
var imagemin = require('gulp-imagemin');
var cache = require('gulp-cache');
var del = require('del');
var runSequence = require('run-sequence');
gulp.task('hello', function() {
console.log('Hello Zell');
});
// Start browserSync server
gulp.task('browserSync', function() {
browserSync.init({
server: {
baseDir: './app',
routes: {
"/bower_components": "bower_components"
}
},
})
})
// SASS Task
gulp.task('sass', function () {
return gulp.src('./app/sass/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'nested', // nested,compact,expanded,compressed
}).on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 2 versions', 'ie >= 9', 'Android >= 2.3', 'Firefox >= 14']
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./app/css'))
.pipe(browserSync.stream())
});
gulp.task('images', function(){
return gulp.src('./app/images/**/*.+(png|jpg|jpeg|gif|svg)')
// Caching images that ran through imagemin
.pipe((imagemin({
interlaced: true
})))
.pipe(gulp.dest('dist/images'))
});
gulp.task('fonts', function() {
return gulp.src('./app/fonts/**/*')
.pipe(gulp.dest('dist/fonts'))
})
// Optimization Tasks
// ------------------
// Optimizing CSS and JavaScript
gulp.task('useref', function() {
return gulp.src('app/*.html')
.pipe(useref())
.pipe(gulpIf('*.js', uglify()))
.pipe(gulpIf('*.css', cssnano()))
.pipe(gulp.dest('dist'));
});
// Watchers
// ------------------
gulp.task('watch', ['browserSync', 'sass'], function (){
gulp.watch('app/sass/**/*.scss', ['sass']);
// Reloads the browser whenever HTML or JS files change
gulp.watch('app/*.html', browserSync.reload);
gulp.watch('app/js/**/*.js', browserSync.reload);
});
// Now Gulp will delete the `dist` folder for you whenever gulp clean:dist is run.
// Cleaning
gulp.task('clean', function() {
return del.sync('dist').then(function(cb) {
return cache.clearAll(cb);
});
})
gulp.task('clean:dist', function() {
return del.sync(['dist/**/*', '!dist/images', '!dist/images/**/*']);
})
gulp.task('default', function (callback) {
runSequence(['sass','browserSync', 'watch' ],
callback
)
})
gulp.task('build', function(callback) {
runSequence(
'clean:dist',
'sass',
['useref', 'images', 'fonts'],
callback
)
})