-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
212 lines (183 loc) · 5.42 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
const { src, dest, series, watch } = require('gulp');
const concat = require('gulp-concat');
const htmlMin = require('gulp-htmlmin');
const autoPrefixer = require('gulp-autoprefixer');
const sass = require('gulp-sass')(require('node-sass'));
const cleanCSS = require('gulp-clean-css');
const svgSprite = require('gulp-svg-sprite');
const imagemin = require('gulp-imagemin');
const webpack = require('webpack');
const webpackStream = require('webpack-stream');
const uglify = require('gulp-uglify-es').default;
const babel = require('gulp-babel');
const notify = require('gulp-notify');
const sourcemaps = require('gulp-sourcemaps');
const del = require('del');
const browserSync = require('browser-sync').create();
const ghPages = require('gh-pages');
const path = require('path');
const clean = () => {
return del(['dist'])
}
const resources = () => {
return src('src/resources/**')
.pipe(dest('dist'))
}
const font = () => {
return src('./src/font/**')
.pipe(dest('dist/font'))
}
const styles = () => {
return src('./src/styles/styles.scss')
.pipe(sass().on('error', notify.onError()))
.pipe(autoPrefixer({
cascade: false
}))
.pipe(concat('main.css'))
.pipe(cleanCSS({
level: 2
}))
.pipe(dest('dist/css'))
}
const stylesDev = () => {
return src('./src/styles/styles.scss')
.pipe(sourcemaps.init())
.pipe(sass().on('error', notify.onError()))
.pipe(concat('main.css'))
.pipe(cleanCSS({
level: 2
}))
.pipe(sourcemaps.write())
.pipe(dest('dist/css'))
.pipe(browserSync.stream())
}
const htmlMinify = () => {
return src('src/**/*.html')
.pipe(htmlMin({
collapseWhitespace: true,
}))
.pipe(dest('dist'))
}
const htmlDev = () => {
return src('src/**/*.html')
.pipe(dest('dist'))
.pipe(browserSync.stream())
}
const svgSprites = () => {
return src('src/images/svg/**/*.svg')
.pipe(svgSprite({
mode: {
stack: {
sprite: ('../sprite.svg')
}
}
}))
.pipe(dest('dist/images'))
}
const scripts = () => {
return src('src/js/main.js')
.pipe(webpackStream({
mode: 'production',
output: {
filename: 'app.js',
},
module: {
rules: [{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}]
},
}))
.on('error', function(err) {
console.error('WEBPACK ERROR', err);
this.emit('end'); // Don't stop the rest of the task
})
.pipe(uglify({
toplevel: true
}).on('error', notify.onError()))
.pipe(dest('dist/js'))
}
const scriptsDev = () => {
return src('src/js/main.js')
.pipe(sourcemaps.init())
.pipe(webpackStream({
mode: 'development',
output: {
filename: 'app.js',
},
module: {
rules: [{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}]
},
}))
.on('error', function(err) {
console.error('WEBPACK ERROR', err);
this.emit('end'); // Don't stop the rest of the task
})
.pipe(sourcemaps.write())
.pipe(dest('dist/js'))
.pipe(browserSync.stream())
}
const images = () => {
return src([
'src/images/**/*.jpg',
'src/images/**/*.png',
'src/images/*.svg',
'src/images/**/*.jpeg',
])
.pipe(imagemin())
.pipe(dest('dist/images'))
}
const imagesDev = () => {
return src([
'src/images/**/*.jpg',
'src/images/**/*.png',
'src/images/*.svg',
'src/images/**/*.jpeg',
])
.pipe(dest('dist/images'))
}
const watchFiles = () => {
browserSync.init({
server: {
baseDir: 'dist'
}
})
}
watch('src/styles/**/*.scss', styles)
watch('src/**/*.html', htmlMinify)
watch('src/images/svg/**/*.svg', svgSprites)
watch('src/js/**/*.js', scripts)
watch('src/resources/**', resources)
// watch('src/**/*.html', htmlDev)
watch('src/**/*.html', htmlDev).on('change', browserSync.reload);
watch('src/styles/**/*.scss', stylesDev)
watch('src/js/**/*.js', scriptsDev)
watch('src/images', imagesDev)
function deploy(cb) {
ghPages.publish(path.join(process.cwd(), './dist'), cb);
}
exports.deploy = deploy;
exports.styles = styles
exports.scripts = scripts
exports.htmlMinify = htmlMinify
exports.stylesDEV = stylesDev
exports.scriptsDev = scriptsDev
exports.htmlDev = htmlDev
exports.imagesDev = imagesDev
exports.prod = series(clean, htmlMinify, scripts, font, styles, images, svgSprites)
exports.dev = series(clean, resources, htmlDev, scriptsDev, font, stylesDev, imagesDev, svgSprites, watchFiles)