-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
98 lines (84 loc) · 2.28 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
var gulp = require('gulp'),
sass = require('gulp-sass'),
browserSync = require('browser-sync'),
concat = require('gulp-concat'),
uglify = require('gulp-uglifyjs'),
cssnano = require('gulp-cssnano'),
rename = require('gulp-rename'),
del = require('del'),
imagemin = require('gulp-imagemin'),
cache = require('gulp-cache'),
autoprefixer = require('gulp-autoprefixer');
function swallowError(error) {
console.log(error.toString());
this.emit('end');
}
gulp.task('sass', function() {
return gulp.src('src/sass/**/*.scss')
.pipe(sass())
.on('error', swallowError)
.pipe(autoprefixer(['last 15 versions', '> 1%', 'ie 8'], { cascade: true }))
.pipe(gulp.dest('src/css'))
.pipe(browserSync.reload({ stream: true }));
});
gulp.task('scripts', function() {
return gulp.src([
'src/libs/jquery/dist/jquery.min.js',
'src/libs/bootstrap/dist/js/bootstrap.min.js',
'src/libs/bootstrap-select/dist/js/bootstrap-select.min.js'
])
.pipe(concat('libs.min.js'))
.pipe(uglify())
.pipe(gulp.dest('src/js'));
});
gulp.task('css-libs', ['sass'], function() {
return gulp.src('src/css/libs.css')
.pipe(cssnano())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('src/css'));
});
gulp.task('browser-sync', function() {
browserSync({
server: {
baseDir: 'src'
},
notify: false
});
});
gulp.task('dist-test', function() {
browserSync({
server: {
baseDir: 'dist'
},
notify: false
});
});
gulp.task('clean', function() {
return del.sync('dist');
});
gulp.task('clear', function() {
return cache.clearAll();
});
gulp.task('img', function() {
return gulp.src('src/img/**/*')
.pipe(cache(imagemin()))
.pipe(gulp.dest('dist/img'));
});
gulp.task('watch', ['browser-sync', 'css-libs', 'scripts'], function() {
gulp.watch('src/sass/**/*.scss', ['sass']);
gulp.watch('src/*.html', browserSync.reload);
gulp.watch('src/js/**/*.js', browserSync.reload);
});
gulp.task('build', ['clean', 'img', 'sass', 'scripts'], function() {
var buildCss = gulp.src([
'src/css/main.css',
'src/css/libs.min.css'
])
.pipe(gulp.dest('dist/css'));
var buildFonts = gulp.src('src/fonts/**/*')
.pipe(gulp.dest('dist/fonts'));
var buildJs = gulp.src('src/js/**/*')
.pipe(gulp.dest('dist/js'));
var buildHtml = gulp.src('src/*.html')
.pipe(gulp.dest('dist'));
});