-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
122 lines (103 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
var gulp = require('gulp'),
compass = require('gulp-compass'),
cssnano = require('gulp-cssnano'),
rename = require("gulp-rename"),
concat = require('gulp-concat'),
htmlmin = require('gulp-htmlmin'),
imagemin = require('gulp-imagemin'),
clean = require('gulp-clean'),
watch = require('gulp-watch'),
gulpsync = require('gulp-sync')(gulp),
browserSync = require("browser-sync").create(),
reload = browserSync.reload,
runSequence = require('run-sequence');
var config = {
'src': './src',
'dest': './dist',
'html': {
'src': './src/*.html',
'dest': './dist/'
},
'sass': {
'src': './src/css/sass/**/*.scss',
'dest': './dist/css/css'
},
'js': {
'src': [
'./node_modules/jquery/dist/jquery.min.js',
'./node_modules/tether/dist/js/tether.min.js',
'./node_modules/bootstrap/dist/js/bootstrap.min.js',
'./node_modules/owl.carousel/dist/owl.carousel.min.js',
'./src/js/*.js'
],
'dest': './dist/js'
},
'img': {
'src': './src/img/*',
'dest': './dist/img/'
},
'fonts': {
'src': './src/fonts/*',
'dest': './dist/fonts/'
}
};
//gulp-htmlmin
gulp.task('minify:html', function() {
return gulp.src(config.html.src)
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest(config.html.dest));
});
gulp.task('styles', function() {
return gulp.src([config.sass.src])
.pipe(compass({
css: config.sass.dest,
sass: 'src/css/sass',
image: config.img.dest
}))
.pipe(rename({ suffix: '.min' }))
.pipe(cssnano())
.pipe(gulp.dest(config.sass.dest))
.pipe(browserSync.reload({
stream: true
}))
});
gulp.task('minify:img', function () {
return gulp.src(config.img.src)
.pipe(imagemin())
.pipe(gulp.dest(config.img.dest));
}
);
gulp.task('fonts', function () {
return gulp.src(config.fonts.src)
.pipe(gulp.dest(config.fonts.dest));
});
gulp.task('js', function () {
return gulp.src(config.js.src)
.pipe(concat('all.min.js'))
.pipe(gulp.dest(config.js.dest));
});
gulp.task('sync', gulpsync.sync(['minify:html', 'styles', 'js']));
gulp.task('clean', function () {
return gulp.src(config.dest, {read: false})
.pipe(clean());
});
gulp.task('build', function (callback) {
runSequence('clean', [ 'sync', 'minify:img','fonts'], callback)
});
gulp.task('browser-sync', ['styles'], function() {
browserSync.init({
server: {
baseDir: config.dest
}
});
});
gulp.task('watch',['browser-sync', 'styles'], function () {
gulp.watch(config.sass.src, ['styles']);
gulp.watch(config.html.src, browserSync.reload);
gulp.watch('src/js/**/*.js', browserSync.reload);
});
gulp.task('default', function (callback) {
runSequence(['styles','browser-sync', 'watch'],
callback
)
});