-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·126 lines (108 loc) · 2.99 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
//github.com/zellwk/gulp-starter-csstricks
var gulp = require("gulp"),
sass = require("gulp-sass"),
browserSync = require("browser-sync"),
useref = require("gulp-useref"),
uglify = require("gulp-uglify"),
gulpIf = require("gulp-if"),
cssnano = require("gulp-cssnano"),
imagemin = require("gulp-imagemin"),
cache = require("gulp-cache"),
addsrc = require("gulp-add-src"),
minifyCSS = require("gulp-minify-css"),
del = require("del"),
runSequence = require("run-sequence");
// Basic Gulp task syntax
gulp.task('hello', function() {
console.log('Hello Zell!');
})
// Development Tasks
// -----------------
// Start browserSync server
gulp.task('browserSync', function() {
browserSync({
server: {
baseDir: 'app'
}
})
})
gulp.task('sass', function() {
return (
gulp
.src("app/scss/**/*.scss") // Gets all files ending with .scss in app/scss and children dirs
.pipe(sass().on("error", sass.logError)) // Passes it through a gulp-sass, log errors to console
.pipe(minifyCSS())
// .pipe(addsrc.prepend("node_modules/bootstrap/dist/css/bootstrap.css"))
.pipe(gulp.dest("app/css")) // Outputs it in the css folder
.pipe(browserSync.reload({ // Reloading with Browser Sync
stream: true }))
);
})
/**
* Minify and combine JS files, including jQuery and Bootstrap
*/
gulp.task('scripts', function () {
gulp.src([
'node_modules/jquery/dist/jquery.js',
'node_modules/bootstrap/dist/js/bootstrap.js',
'src/js/**/*.js'
])
//.pipe(uglify())
//.pipe(concat('script.js'))
.pipe(gulp.dest('app/js'));
});
// Watchers
gulp.task('watch', function() {
gulp.watch('app/scss/**/*.scss', ['sass']);
gulp.watch("app/css/*.css", browserSync.reload);
gulp.watch('app/*.html', browserSync.reload);
gulp.watch('app/js/**/*.js', browserSync.reload);
})
// 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'));
});
// Optimizing Images
gulp.task('images', function() {
return gulp.src('app/images/**/*.+(png|jpg|jpeg|gif|svg)')
// Caching images that ran through imagemin
.pipe(cache(imagemin({
interlaced: true,
})))
.pipe(gulp.dest('dist/images'))
});
// Copying fonts
gulp.task('fonts', function() {
return gulp.src('app/fonts/**/*')
.pipe(gulp.dest('dist/fonts'))
})
// 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/**/*']);
});
// Build Sequences
// ---------------
gulp.task('default', function(callback) {
runSequence(['sass', 'browserSync'], 'watch',
callback
)
})
gulp.task('build', function(callback) {
runSequence(
'clean:dist',
'sass',
['useref', 'images', 'fonts'],
callback
)
})