-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
159 lines (133 loc) · 3.54 KB
/
gulpfile.js
File metadata and controls
159 lines (133 loc) · 3.54 KB
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
const config = require('./config/dimple.config')
const gulp = require('gulp')
const sourcemaps = require('gulp-sourcemaps')
const sass = require('gulp-sass')
const svgSprite = require('gulp-svg-sprite')
const webpack = require('webpack')
const webpackConfig = require('./config/webpack.config')
const webserver = require('gulp-webserver')
/* ************************************************************************************ */
// ******************
// Assets tasks
// ******************
const processAssets = () => {
return gulp.src([config.assets.entry]).pipe(gulp.dest(config.assets.output))
}
const watchAssets = () => {
gulp.watch([config.assets.entry], processAssets)
}
// ******************
// HTML tasks
// ******************
const processHTML = () => {
return gulp.src([config.html.entry]).pipe(gulp.dest(config.html.output))
}
const watchHTML = () => {
gulp.watch([config.html.entry], processHTML)
}
// ******************
// FAVICON tasks
// ******************
const processFavicon = () => {
return gulp.src([config.favicon.entry]).pipe(gulp.dest(config.favicon.output))
}
const watchFavicon = () => {
gulp.watch([config.favicon.entry], processFavicon)
}
// ******************
// SVG tasks
// ******************
const processSVGs = () => {
return gulp
.src([config.svgs.entry])
.pipe(
svgSprite({
mode: {
stack: true
},
svg: {
// General options for created SVG files
xmlDeclaration: false, // Add XML declaration to SVG sprite
doctypeDeclaration: false
}
})
) // Activate Sass output (with default options) // Activate the «symbol» mode
.pipe(gulp.dest(config.svgs.output))
}
const watchSVGs = () => {
gulp.watch([config.svgs.entry], processSVGs)
}
// ******************
// SASS tasks
// ******************
const processSass = () => {
return gulp
.src(config.sass.entry)
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.sass.output))
}
const watchSass = () => {
gulp.watch([config.sass.watch], processSass)
}
// ******************
// JS tasks
// ******************
function webpackScripts() {
webpackConfig.mode = 'development'
return new Promise(resolve =>
webpack(webpackConfig, (err, stats) => {
if (err) console.log('Webpack', err)
console.log(
stats.toString({
/* stats options */
})
)
resolve()
})
)
}
const processJS = gulp.series(webpackScripts)
const watchJS = () => {
gulp.watch([config.js.watch], processJS)
}
/* ************************************************************************************ */
// ******************
// Dev Server
// ******************
const serve = () => {
return gulp.src('build').pipe(
webserver({
port: config.server.port,
livereload: true,
// host: '0.0.0.0',
open: true
})
)
}
/* ************************************************************************************ */
// Watch
const watchTask = gulp.parallel(
watchSass,
watchJS,
watchAssets,
watchSVGs,
watchHTML,
watchFavicon
)
watchTask.description = 'watch for changes to all source'
// Process
const processTask = gulp.parallel(
processSass,
processJS,
processAssets,
processSVGs,
processHTML,
processFavicon
)
// default task
const defaultTask = gulp.series(processTask, gulp.parallel(watchTask, serve))
gulp.task('default', defaultTask)
gulp.task('build', processTask)
gulp.task('watch', watchTask)