This repository has been archived by the owner on Nov 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
167 lines (142 loc) · 4.07 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
const {
src,
dest,
parallel,
series,
watch,
lastRun
} = require('gulp');
// Load plugins
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const less = require('gulp-less');
const autoprefixer = require('gulp-autoprefixer');
const cssnano = require('gulp-cssnano');
const concat = require('gulp-concat');
const clean = require('gulp-clean');
const imagemin = require('gulp-imagemin');
const changed = require('gulp-changed');
const gulpif = require('gulp-if');
const preprocess = require('gulp-preprocess');
const htmlmin = require('gulp-htmlmin');
const browsersync = require('browser-sync').create();
const srcLess = './src/less/*.less';
const srcLessAndModules = './src/less/**';
const srcHtml = './src/html/*.html';
const srcHtmlAndModules = './src/html/**';
const srcImages = './src/images/**';
const srcAudio = './src/audio/*';
const srcFonts = './src/fonts/*';
const srcJs = './src/js/*.js';
const srcJsStatic = './src/js/vendor/*.js';
const srcJsMapping = [
{ inputs: ['./src/js/menu.js', './src/js/modal.js'], output: 'common.js' },
{ inputs: ['./src/js/home-common.js', './src/js/player.js'], output: 'home.js' },
{ inputs: ['./src/js/work-info.js'], output: 'our-work.js' },
{ inputs: ['./src/js/overlay.js'], output: 'info.js' },
{ inputs: ['./src/js/thank-you.js'], output: 'thank-you.js' },
];
// Clean assets
function clear() {
return src('./dist/*', { read: false })
.pipe(clean());
}
// JS function
function js (done) {
const combine = (inputs, output) => {
return src(inputs)
//.pipe(changed(inputs))
.pipe(concat(output))
.pipe(dest('./dist/js/'))
.pipe(uglify())
.pipe(rename({
extname: '.min.js'
}))
.pipe(dest('./dist/js/'))
//.pipe(browsersync.stream());
}
const combineTasks = srcJsMapping.map(obj => {
return taskDone => {
combine(obj.inputs, obj.output)
taskDone()
}
});
const vendorTask = taskDone => {
src(srcJsStatic).pipe(uglify()).pipe(rename({ extname: '.min.js' })).pipe(dest('./dist/js/vendor/'))
taskDone();
};
return series(...combineTasks, vendorTask, seriesDone => {
seriesDone();
done();
})();
}
// CSS function
function css() {
return src(srcLess)
.pipe(changed(srcLess))
.pipe(less())
.pipe(autoprefixer({
overrideBrowserslist: ['last 2 versions'],
cascade: false
}))
.pipe(rename({
extname: '.min.css'
}))
.pipe(cssnano())
.pipe(dest('./dist/css/'))
.pipe(browsersync.stream());
}
// HTML function
function html() {
return src(srcHtml)
.pipe(preprocess())
//.pipe(htmlmin({collapseWhitespace: true}))
.pipe(dest('./dist/'))
}
// Optimize images
function images() {
return src(srcImages, {since: lastRun(images)})
.pipe(imagemin())
.pipe(dest('./dist/images'));
}
// Static assets
function fonts () {
return src(srcFonts, { since: lastRun(fonts) })
.pipe(dest('./dist/fonts'));
}
function audio () {
return src(srcAudio, { since: lastRun(audio) })
.pipe(dest('./dist/audio'));
}
// Watch files
function watchFiles() {
watch(srcLessAndModules, css);
watch(srcJs, js);
watch(srcImages, images);
watch(srcHtmlAndModules, html);
watch(srcAudio, audio);
watch(srcFonts, fonts);
}
// BrowserSync
function browserSync() {
browsersync.init({
server: {
baseDir: './dist/',
index: "home.html",
serveStaticOptions: {
extensions: ["html"]
}
},
port: process.env.PORT || 8084,
open: false,
rewriteRules: [
{
match: /src=\"js\/([a-zA-Z0-9\-]+).min.js\"/g,
replace: "src=\"js/$1.js\""
}
]
});
}
const build = series(clear, parallel(js, css, images, html, audio, fonts));
exports.watch = series(build, parallel(watchFiles, browserSync));
exports.default = build;