-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.babel.js
90 lines (77 loc) · 2.1 KB
/
gulpfile.babel.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
import gulp from 'gulp';
import autoprefixer from 'gulp-autoprefixer';
import cleanCSS from 'gulp-clean-css';
import imagemin from 'gulp-imagemin';
import pug from 'gulp-pug';
import sass from 'gulp-sass';
import sourcemaps from 'gulp-sourcemaps';
import del from 'del';
import webpack from 'webpack-stream';
import browserSync from 'browser-sync';
const paths = {
styles: {
src: 'src/styles/**/*.scss',
dest: 'dist/styles/',
},
scripts: {
src: 'src/scripts/**/*.js',
dest: 'dist/scripts/',
},
images: {
src: 'src/images/**/*.{jpg,jpeg,png}',
dest: 'dist/images/',
},
};
export const clean = () => del(['dist']);
export function serve() {
return browserSync.init({
server: {
baseDir: './dist',
},
open: false,
});
}
export function styles() {
return gulp
.src(paths.styles.src)
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({ cascade: false }))
.pipe(cleanCSS())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.styles.dest))
.pipe(browserSync.stream());
}
export function scripts() {
return gulp
.src(paths.scripts.src)
.pipe(webpack(require('./webpack.config.js')))
.pipe(gulp.dest(paths.scripts.dest))
.pipe(browserSync.stream());
}
export function images() {
return gulp
.src(paths.images.src, { since: gulp.lastRun(images) })
.pipe(imagemin({ optimizationLevel: 5 }))
.pipe(gulp.dest(paths.images.dest))
.pipe(browserSync.stream());
}
export function views() {
return gulp
.src('src/index.pug')
.pipe(pug())
.pipe(gulp.dest('dist'))
.pipe(browserSync.stream());
}
export function watch() {
gulp.watch(paths.styles.src, styles);
gulp.watch(paths.scripts.src, scripts);
gulp.watch(paths.images.src, images);
gulp.watch('src/index.pug', views);
gulp.watch('dist/index.html').on('change', browserSync.reload);
}
const build = gulp.series(clean, gulp.parallel(styles, scripts, images, views));
const defaultTask = gulp.parallel(build, serve, watch);
gulp.task('build', build);
gulp.task('default', defaultTask);
export default defaultTask;