-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
96 lines (85 loc) · 2.35 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
const {series, dest, src, watch} = require('gulp')
const twig = require('gulp-twig')
const sass = require('gulp-sass')(require('sass'))
const sourcemap = require('gulp-sourcemaps')
const browsersync = require('browser-sync').create()
const concat = require('gulp-concat')
const uglify = require('gulp-uglify')
const clean = require('gulp-clean')
// Template engine twig
function templateTask(){
return src('./src/*.twig')
.pipe(twig()).pipe(dest('dist'))
}
// SCSS Styles
function styleTask(){
return src('./src/scss/*.scss')
.pipe(sourcemap.init())
.pipe(sass({outputStyle: 'compressed'}))
.pipe(sourcemap.write('.'))
.pipe(dest('dist/assets/css')).pipe(browsersync.stream())
}
// CSS Styles
function cssPluginTask(){
return src('./src/assets/css/*.css')
.pipe(concat('plugins.min.css'))
.pipe(dest('dist/assets/css'))
}
// Image asssets
function imageTask(){
return src('./src/assets/img/**')
.pipe(dest('dist/assets/img'))
}
// js asssets
function jsPluginsTask(){
return src(['./src/assets/js/**/*.js', '!src/assets/js/scripts.js'])
.pipe(concat('app.min.js'))
.pipe(uglify())
.pipe(dest('dist/assets/js'))
}
// Custom JS task
function customJsTask(){
return src('src/assets/js/scripts.js')
.pipe(dest('dist/assets/js'))
}
// Fonts file
function custonFonts(){
return src('src/assets/fonts/**')
.pipe(dest('dist/assets/fonts'))
}
// Live reload browsersync
function browsersyncServe(cb){
browsersync.init({
server: {
baseDir: './dist'
}
})
cb()
}
// Destroy dist folder
function destroyDist(){
return src('./dist/', {read: true, allowEmpty: true}).pipe(clean());
}
// Watch all files
function watcher(){
watch('./src/**/*.twig').on("change", series(templateTask, browsersync.reload))
watch('./src/assets/img/**', imageTask)
watch('./src/assets/js/**/*.js', jsPluginsTask)
watch('./src/assets/js/scripts.js', customJsTask)
watch('./src/assets/css/*.css', cssPluginTask)
watch('./src/scss/**/*.scss', styleTask)
watch('./src/assets/fonts/**', custonFonts)
}
// Default series task
exports.default = series(
destroyDist,
templateTask,
styleTask,
cssPluginTask,
imageTask,
jsPluginsTask,
customJsTask,
custonFonts,
browsersyncServe,
watcher
)