-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
72 lines (63 loc) · 2.02 KB
/
gulpfile.js
File metadata and controls
72 lines (63 loc) · 2.02 KB
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
const gulp = require('gulp');
const gulpSass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const browserSync = require('browser-sync').create();
const useref = require('gulp-useref');
const uglify = require('gulp-uglify');
const cssnano = require('gulp-cssnano');
const imagemin = require('gulp-imagemin');
const cache = require('gulp-cache');
const gulpIf = require('gulp-if');
const del = require('del');
const runSequence = require('run-sequence');
gulp.task('build:css', function () {
return gulp.src('src/scss/**/*.scss')
.pipe(gulpSass())
.pipe(autoprefixer())
.pipe(gulp.dest('src/css'))
.pipe(browserSync.reload({
stream: true
}));
});
gulp.task('build:fonts', function () {
return gulp.src('src/fonts/**/*')
.pipe(gulp.dest('dist/fonts'));
});
gulp.task('build:images', function () {
return gulp.src('app/images/**/*.+(png|jpg|gif|svg)')
.pipe(cache(imagemin({
interlaced: true
})))
.pipe(gulp.dest('dist/images'));
});
gulp.task('build:bundle', function () {
return gulp.src('src/*.html')
.pipe(useref())
.pipe(gulpIf('*.js', uglify()))
.pipe(gulpIf('*.css', cssnano()))
.pipe(gulp.dest('dist'))
.pipe(browserSync.reload({
stream: true
}));
});
gulp.task('browserSync', function () {
browserSync.init({
server: {
baseDir: 'dist'
}
});
});
gulp.task('clean:dist', function () {
return del.sync('dist');
});
gulp.task('cache:clear', function () {
return cache.clearAll()
});
gulp.task('build', function () {
runSequence('clean:dist', ['build:css', 'build:images', 'build:fonts'], 'build:bundle');
});
gulp.task('watch', ['browserSync', 'build'], function () {
gulp.watch('src/scss/**/*.scss', ['build:css', 'build:bundle']);
gulp.watch('src/*.html', ['build:bundle']);
gulp.watch('src/js/**/*.js', ['build:bundle']);
});