-
Notifications
You must be signed in to change notification settings - Fork 15
/
gulpfile.js
117 lines (93 loc) · 2.44 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
// Include gulp
var gulp = require('gulp');
// Include plugins
// npm install --save-dev gulp-sass gulp-autoprefixer gulp-minify-css gulp-concat gulp-uglify gulp-imagemin browser-sync gulp-cache gulp-notify gulp-size gulp-rename
var sass = require('gulp-sass');
var prefix = require('gulp-autoprefixer');
var minifycss = require('gulp-minify-css');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var images = require('gulp-imagemin');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var cache = require('gulp-cache');
var notify = require('gulp-notify');
var size = require('gulp-size');
var rename = require('gulp-rename');
// Default Task
gulp.task('default', ['css', 'js', 'images', 'browser-sync', 'watch']);
// Tasks
// Compile sass
gulp.task('css', function() {
gulp.src('scss/**/*.scss')
.pipe(sass({
errLogToConsole: true
}))
// auto prefix css
.pipe(prefix('last 2 versions'))
// move css file to folder
.pipe(gulp.dest('css/'))
// rename the file with .min
.pipe(rename({
suffix: '.min'
}))
// minify the file
.pipe(minifycss())
// move minified css file to folder
.pipe(gulp.dest('css/'))
// get file size (gzipped)
.pipe(size({
gzip: true
}))
// notify to say the task has complete
.pipe(notify({
message: 'CSS task complete'
}))
});
// Concatenate js files and minify
gulp.task('js', function() {
gulp.src('js/*.js')
.pipe(concat('bundle.js'))
// minify the file
.pipe(uglify())
// move js file to folder
.pipe(gulp.dest('js/min/'))
// notify to say the task has complete
.pipe(notify({
message: 'JS task complete'
}))
});
// Compress images
gulp.task('images', function() {
gulp.src('img/*.{gif,jpg,png}')
.pipe(cache(images({
optimizationLevel: 4,
progressive: true,
interlaced: true
})))
.pipe(gulp.dest('img/min/'))
// notify to say the task has complete
.pipe(notify({
message: 'Images task complete'
}))
});
// Reload browser
gulp.task('reload', function () {
browserSync.reload();
});
// Prepare Browser-sync
gulp.task('browser-sync', function() {
browserSync.init(['scss/**/*.scss', 'js/*.js'], {
//proxy: 'your_dev_site.url'
server: {
baseDir: './'
}
});
});
// Watch files for changes
gulp.task('watch', function() {
gulp.watch('scss/**/*.scss', ['css']);
gulp.watch('js/*.js', ['js']);
gulp.watch('img/*' , ['images']);
gulp.watch(['*.html'], ['reload']);
});