-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
215 lines (195 loc) · 5.4 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
213
214
215
const gulp = require('gulp')
const gulpIf = require('gulp-if')
const clean = require('gulp-clean')
const fileInclude = require('gulp-file-include')
const htmlmin = require('gulp-htmlmin')
const sass = require('gulp-sass')
const cssmin = require('gulp-cssmin')
const purgecss = require('gulp-purgecss')
const autoprefixer = require('gulp-autoprefixer')
const rollup = require('gulp-better-rollup')
const sourcemaps = require('gulp-sourcemaps')
const babel = require('rollup-plugin-babel')
const resolve = require('rollup-plugin-node-resolve')
const commonjs = require('rollup-plugin-commonjs')
const terser = require('rollup-plugin-terser').terser
const responsive = require('gulp-responsive')
const sitemap = require('gulp-sitemap')
const browserSync = require('browser-sync').create()
const isProd = process.env.NODE_ENV === 'prod'
const html = () => {
return gulp
.src(['src/pages/**/*.html'])
.pipe(fileInclude({
prefix: '@@',
basePath: '@file'
}))
.pipe(gulpIf(isProd, htmlmin({
collapseWhitespace: true
})))
.pipe(gulp.dest('docs'))
}
const sitemapXml = () => {
return gulp
.src('src/pages/**/*.html', {
read: false
})
.pipe(sitemap({
siteUrl: 'https://dailybrain.fr'
}))
.pipe(gulp.dest('docs'))
}
const assets = () => {
return gulp
.src(['src/assets/**/*', 'src/favicons/*'])
.pipe(gulp.dest('docs'))
}
const jpg = () => {
return gulp
.src('src/img/**/*.jpg')
.pipe(
responsive(
{
'**/*.jpg': [
{
}
],
'landings/*.jpg': [
{
width: 600,
rename: { suffix: '-600px' }
},
{
width: 800,
rename: { suffix: '-800px' }
},
{
width: 1000,
rename: { suffix: '-1000px' }
},
{
width: 1200,
rename: { suffix: '-1200px' }
},
{
width: 1400,
rename: { suffix: '-1400px' }
},
{
width: 1920,
rename: { suffix: '-1920px' }
}
],
'testimonials/*.jpg': [
{
width: 60
}
]
},
// default settings for all
{
quality: 85,
progressive: true,
withMetadata: false
}
)
)
.pipe(gulp.dest('docs/img'))
}
const png = () => {
return gulp
.src('src/img/**/*.png')
.pipe(gulp.dest('docs/img'))
}
const svg = () => {
return gulp
.src('src/img/**/*.svg')
.pipe(gulp.dest('docs/img'))
}
const images = async () => {
return await [
jpg(),
png(),
svg()
]
}
const css = () => {
return gulp
.src('src/sass/*.scss')
.pipe(gulpIf(!isProd, sourcemaps.init()))
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer())
.pipe(gulpIf(!isProd, sourcemaps.write('')))
.pipe(gulpIf(isProd, purgecss({
content: [
'src/partials/**/*.html',
'src/pages/**/*.html'
],
safelist: {
standard: [
'navbar-dark',
'navbar-light',
'pulse'
],
deep: [/^carousel/,/^aos/,/^data-aos/,/^btn-scroll-top/]
},
})))
.pipe(gulpIf(isProd, cssmin()))
.pipe(gulp.dest('docs/css'))
}
const js = () => {
return gulp
.src('src/js/*.js')
.pipe(gulpIf(!isProd, sourcemaps.init()))
.pipe(gulpIf(!isProd, rollup({ plugins: [babel(), resolve(), commonjs()] }, 'umd')))
.pipe(gulpIf(isProd, rollup({
plugins: [
babel(),
resolve(),
commonjs(),
terser(
{
format: {
comments: false
},
compress: {
drop_console: true
}
}
)
]
},
'umd'
)
))
.pipe(gulpIf(!isProd, sourcemaps.write('')))
.pipe(gulp.dest('docs/js'))
}
const del = () => {
return gulp
.src('docs/*', { read: false })
.pipe(clean())
}
const serve = () => {
browserSync.init({
open: false,
server: './docs'
})
}
const browserSyncReload = (done) => {
browserSync.reload()
done()
}
const watchFiles = () => {
gulp.watch('src/**/*.html', gulp.series(html, browserSyncReload))
gulp.watch('src/**/*.scss', gulp.series(css, browserSyncReload))
gulp.watch('src/**/*.js', gulp.series(js, browserSyncReload))
gulp.watch('src/img/**/*.*', gulp.series(images))
return
}
exports.html = html
exports.css = css
exports.js = js
exports.del = del
exports.serve = gulp.parallel(html, sitemapXml, assets, images, css, js, watchFiles, serve)
exports.default = gulp.series(del, html, sitemapXml, assets, images, css, js)