-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
108 lines (96 loc) · 2.3 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
import gulp from 'gulp'
import browserSync from 'browser-sync'
import notify from 'gulp-notify'
import htmlmin from 'gulp-htmlmin'
import dartSass from 'sass'
import gulpSass from 'gulp-sass'
import cleancss from 'gulp-clean-css'
import autoprefixer from 'gulp-autoprefixer'
import rename from 'gulp-rename'
import webpackStream from 'webpack-stream'
import svgSprite from 'gulp-svg-sprite'
import del from 'del'
const sass = gulpSass(dartSass)
function server() {
browserSync.init({
server: {
baseDir: 'dist'
},
open: false,
// tunnel: true,
})
}
function styles() {
return gulp.src('src/sass/**/*.sass')
.pipe(sass({
quietDeps: true
}).on("error", notify.onError()))
.pipe(rename({ suffix: '.min' }))
.pipe(autoprefixer(['last 15 versions']))
.pipe(cleancss())
.pipe(gulp.dest('dist/css'))
.pipe(browserSync.stream())
}
function scripts() {
return gulp.src('src/js/app.js')
.pipe(webpackStream({
mode: 'production',
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
}
}))
.pipe(rename('app.min.js'))
.pipe(gulp.dest('dist/js'))
.pipe(browserSync.stream())
}
function html() {
return gulp.src('src/*.html')
.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true
}))
.pipe(gulp.dest('dist'))
.pipe(browserSync.stream())
}
function svg() {
return gulp.src('src/img/svg/*.svg')
.pipe(svgSprite({
mode: {
stack: {
sprite: '../sprite.svg'
}
}
}))
.pipe(gulp.dest('src/img'))
}
function copy() {
return gulp.src(['src/fonts/**/*', 'src/img/!(svg)/**/*', 'src/img/!(svg)'], { base: 'src' })
.pipe(gulp.dest('dist'))
.pipe(browserSync.stream({
once: true
}))
}
function clean() {
return del('dist')
}
function startWatch() {
gulp.watch(['src/fonts/**/*', 'src/img/**/*', '!src/img/!(svg)/*'], copy)
gulp.watch(['src/img/svg/*'], svg)
gulp.watch('src/sass/**/*.s[ac]ss', styles)
gulp.watch(['src/js/*', '!src/js/**/*.min.js'], scripts)
gulp.watch('src/*.html', html)
}
export { svg }
export let build = gulp.series(clean, scripts, styles, copy, html)
export default gulp.series(clean, gulp.parallel(html, styles, scripts, copy), gulp.parallel(server, startWatch))