-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
126 lines (109 loc) · 2.87 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const gulp = require('gulp')
const del = require('del')
// ...
const plumber = require('gulp-plumber')
const imageMin = require('gulp-imagemin')
const chainStyle = require('./gulpchainstyle')
const chainScripts = require('./gulpchainscripts')
// twig
const twig = require('gulp-twig')
const changed = require('gulp-changed')
const htmlBeautify = require('gulp-html-beautify')
//webpack
const webpack = require('webpack')
const webpackStream = require('webpack-stream')
// const
const browserSync = require('browser-sync').create()
const templatePath = './public'
gulp.task('vue', function() {
// При работе с vue удалить return
return new Promise(function(resolve) {
resolve()
})
return gulp.src('./src/vue/index.js')
.pipe(webpackStream(require('./webpack.config'), webpack))
.pipe(gulp.dest(templatePath + '/assets/js'))
})
gulp.task('json', () => {
return gulp.src('./src/**/*.{json,json5}')
.pipe(gulp.dest(templatePath + '/assets/json'))
})
gulp.task('html', () => {
return gulp.src('./src/*.twig')
.pipe(plumber())
.pipe(changed('./src/*.twig'))
.pipe(twig())
.pipe(htmlBeautify({ indentSize: 4 }))
.pipe(gulp.dest(templatePath))
})
gulp.task('images', () => {
return gulp
.src(['./src/images/**/*.{png,jpg,jpeg,webp,svg,ico}'])
.pipe(
imageMin([
imageMin.optipng({ optimizationLevel: 3 }),
imageMin.mozjpeg({ quality: 75, progressive: true }),
imageMin.svgo()
])
)
.pipe(gulp.dest(templatePath + '/assets/images'))
})
gulp.task('copy', () => {
return gulp
.src([
'./src/**/*.{eot,ttf,woff,woff2,png,jpg,jpeg,webp,svg,ico}',
'./src/js/vendor/**/*.js'
], {
base: 'src'
})
.pipe(gulp.dest(templatePath + '/assets'))
})
gulp.task('styles', () => {
return chainStyle([
'./src/sass/style.scss'
], templatePath + '/assets', browserSync)
})
gulp.task('scripts', () => {
return chainScripts([
'./src/js/polyfill/*.js',
'./src/js/functions/*.js',
'./src/js/legancy/*.js',
'./src/js/index.js',
'!./src/js/**/*.min.js'
], templatePath + '/assets', browserSync)
})
gulp.task('clean', () => {
return del(templatePath)
})
gulp.task('serve', () => {
browserSync.init({
server: templatePath
})
gulp.watch('./src/**/*.{json,json5}', gulp.series('json'))
gulp.watch('./src/sass/**/*.scss', gulp.series('styles'))
gulp.watch('./src/**/*.twig', gulp.series('html', 'reload'))
gulp.watch(['./src/js/**/*.js', '!./src/js/**/*.min.js'], gulp.series('scripts', 'reload'))
gulp.watch('src/vue/**/*.{js,vue}', gulp.series('vue', 'reload'))
})
gulp.task('reload', done => {
browserSync.reload()
done()
})
gulp.task('build', gulp.series(
'clean',
'copy',
'images',
'styles',
'scripts',
'vue',
'html'
))
gulp.task('start', gulp.series(
'clean',
'copy',
'styles',
'scripts',
'vue',
'html',
'serve'
))