-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
77 lines (68 loc) · 1.71 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
const gulp = require('gulp'),
clean = require('gulp-clean'),
sass = require('gulp-sass'),
concat = require('gulp-concat'),
babel = require('gulp-babel'),
uglify = require('gulp-uglify'),
minifyCSS = require('gulp-clean-css'),
prefixer = require('gulp-autoprefixer'),
imagemin = require('gulp-imagemin'),
browserSync = require('browser-sync').create();
const path = {
src: {
scss: 'src/scss/*.scss',
js: 'src/js/*.js',
img: 'src/img/**/*'
},
dist: {
self: './dist',
css: 'dist/css/',
js: 'dist/js/',
img: 'dist/img/'
},
watch: {
scss: 'src/**/*.scss'
}
};
const cleanDist = () =>
gulp.src(path.dist.self, { allowEmpty: true }).pipe(clean());
const buildIMG = () =>
gulp
.src(path.src.img)
.pipe(imagemin())
.pipe(gulp.dest(path.dist.img));
const buildSCSS = () =>
gulp
.src(path.src.scss)
.pipe(sass().on('error', sass.logError))
.pipe(
prefixer({
cascade: false
})
)
.pipe(minifyCSS({ compatibility: 'ie8' }))
.pipe(concat('style.min.css'))
.pipe(gulp.dest(path.dist.css));
const buildJS = () =>
gulp
.src(path.src.js)
.pipe(concat('script.min.js'))
.pipe(
babel({
presets: ['@babel/env']
})
)
.pipe(uglify())
.pipe(gulp.dest(path.dist.js));
const watcher = () => {
browserSync.init({
server: {
baseDir: './'
}
});
gulp.watch(path.watch.scss, buildSCSS).on('change', browserSync.reload);
gulp.watch(path.src.js, buildJS).on('change', browserSync.reload);
gulp.watch(path.src.img, buildIMG).on('change', browserSync.reload);
};
gulp.task('build', gulp.series(cleanDist, buildSCSS, buildJS, buildIMG));
gulp.task('dev', gulp.series(watcher));