-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
111 lines (96 loc) · 3.58 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
let preprocessor = 'sass'; // Preprocessor (sass, scss, less, styl)
let fileswatch = 'html,htm,txt,json,md,woff2'; // List of files extensions for watching & hard reload (comma separated)
let imageswatch = 'jpg,jpeg,png,webp,svg'; // List of images extensions for watching & compression (comma separated)
const { src, dest, parallel, series, watch, lastRun } = require('gulp');
const sass = require('gulp-sass')(require('sass'));
const scss = require('gulp-sass')(require('sass'));
const less = require('gulp-less');
const styl = require('gulp-stylus');
const cleancss = require('gulp-clean-css');
const concat = require('gulp-concat');
const browserSync = require('browser-sync').create();
const uglify = require('gulp-uglify-es').default;
const autoprefixer = require('gulp-autoprefixer');
const imagemin = require('gulp-imagemin');
const newer = require('gulp-newer');
const rsync = require('gulp-rsync');
const del = require('del');
// Local Server
function browsersync() {
browserSync.init({
server: { baseDir: 'app' },
notify: false,
// online: false, // Work offline without internet connection
});
}
// Custom Styles
function styles() {
return src('app/' + preprocessor + '/main.*')
.pipe(eval(preprocessor)())
.pipe(concat('app.min.css'))
.pipe(autoprefixer({ overrideBrowserslist: ['last 10 versions'], grid: true }))
.pipe(cleancss({ level: { 1: { specialComments: 0 } } }))
.pipe(dest('app/css'))
.pipe(browserSync.stream());
}
// Scripts & JS Libraries
function scripts() {
return src([
'node_modules/jquery/dist/jquery.min.js', // jQuery Lib
'node_modules/swiper/js/swiper.min.js', // Swiper Carousel
'node_modules/vanilla-lazyload/dist/lazyload.min.js', // LazyLoad
'node_modules/bootstrap/js/dist/util.js', // Bootstrap Lib Util
'node_modules/bootstrap/js/dist/modal.js', // Bootstrap Modal
'node_modules/bootstrap/js/dist/tab.js', // Bootstrap Tabs
'app/libs/popper.min.js', // Lib Popper
'app/libs/fancybox/dist/jquery.fancybox.min.js', // Fancybox 3
'app/libs/jquery.inputmask.min.js', // jQuery Inputmask
'app/libs/jquery.marquee.min.js', // Marquee String
'app/js/app.js', // Main JS
])
.pipe(concat('app.min.js'))
.pipe(uglify()) // Minify JS (opt.)
.pipe(dest('app/js'))
.pipe(browserSync.stream());
}
// Images
function images() {
return src('app/images/src/**/*')
.pipe(newer('app/images/dest'))
.pipe(imagemin())
.pipe(dest('app/images/dest'));
}
function cleanimg() {
return del('app/images/dest/**/*', { force: true });
}
// Deploy
function deploy() {
return src('app/').pipe(
rsync({
root: 'app/',
hostname: '[email protected]',
destination: 'yousite/public_html/',
// include: ['*.htaccess'], // Included files
exclude: ['**/Thumbs.db', '**/*.DS_Store'], // Excluded files
recursive: true,
archive: true,
silent: false,
compress: true,
}),
);
}
// Watching
function startwatch() {
watch('app/' + preprocessor + '/**/*', styles);
watch(['app/**/*.js', '!app/js/*.min.js'], scripts);
watch(['app/**/*.{' + imageswatch + '}'], images);
watch(['app/**/*.{' + fileswatch + '}']).on('change', browserSync.reload);
}
exports.browsersync = browsersync;
exports.assets = series(cleanimg, styles, scripts, images);
exports.styles = styles;
exports.scripts = scripts;
exports.images = images;
exports.cleanimg = cleanimg;
exports.deploy = deploy;
exports.default = parallel(images, styles, scripts, browsersync, startwatch);