-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·104 lines (96 loc) · 2.66 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
// Gulpfile
"use strict";
const gulp = require('gulp');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const rename = require('gulp-rename');
const concat = require('gulp-concat');
const cleanCSS = require('gulp-clean-css');
const uglify = require('gulp-uglify-es').default;
const browsersync = require('browser-sync').create();
// Gulp plumber error handler - displays if any error occurs during the process on your command
function errorLog(error) {
console.error.bind(error);
this.emit('end');
}
// SASS - Compile SASS files into CSS
function scss() {
return gulp
.src('./assets/scss/**/*.scss')
.pipe(sass({outputStyle: 'expanded'}))
.pipe(cleanCSS({compatibility: 'ie11'}))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('./assets/css/'))
.on('error', sass.logError)
.pipe(autoprefixer([
"last 1 major version",
">= 1%",
"Chrome >= 45",
"Firefox >= 38",
"Edge >= 12",
"Explorer >= 10",
"iOS >= 9",
"Safari >= 9",
"Android >= 4.4",
"Opera >= 30"], {cascade: true}))
.pipe(gulp.dest('./assets/css/'))
.pipe(browsersync.stream());
}
// BrowserSync (live reload) - keeps multiple browsers & devices in sync when building websites
function browserSync(done) {
browsersync.init({
files: "./*.html",
startPath: "./index.html",
server: {
baseDir: "./",
routes: {},
middleware: function (req, res, next) {
if (/\.json|\.txt|\.html/.test(req.url) && req.method.toUpperCase() == 'POST') {
console.log('[POST => GET] : ' + req.url);
req.method = 'GET';
}
next();
}
}
});
done();
}
function browserSyncReload(done) {
browsersync.reload();
done();
}
// Gulp Watch and Tasks
function watch() {
gulp.watch('./assets/scss/**/*.scss', scss);
gulp.watch(
[
'./*.html',
'./html/**/*.html'
],
gulp.series(browserSyncReload)
);
}
// JavaSript minifier - merges and minifies the below given list of Space libraries into one theme.min.js
function minJS() {
return gulp
.src([
'./assets/js/theme-custom.js',
])
.pipe(concat('theme.min.js'))
.pipe(uglify())
.pipe(gulp.dest('./assets/js/dist/'));
}
// Copy Vendors - a utility to copy client-side dependencies into a folder
function copyVendors() {
return gulp
.src([
'./node_modules/*bootstrap/**/*',
'./node_modules/*aos/**/*',
])
.pipe(gulp.dest('./assets/vendor/'))
}
// Gulp Tasks
gulp.task('default', gulp.parallel(watch, scss, browserSync));
gulp.task('minJS', minJS);
gulp.task('copyVendors', copyVendors);
gulp.task('dist', gulp.series(copyVendors, minJS));