This repository has been archived by the owner on Dec 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
150 lines (130 loc) · 4.3 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
var gulp = require('gulp'),
sass = require('gulp-sass'),
browserSync = require('browser-sync').create(),
concat = require('gulp-concat'),
uglify = require('gulp-uglify-es').default,
cleancss = require('gulp-clean-css'),
autoprefixer = require('gulp-autoprefixer'),
rsync = require('gulp-rsync'),
newer = require('gulp-newer'),
rename = require('gulp-rename'),
responsive = require('gulp-responsive'),
del = require('del');
// Local Server
gulp.task('browser-sync', function() {
browserSync.init({
server: {
baseDir: 'app'
},
notify: false,
// online: false, // Work offline without internet connection
// tunnel: true, tunnel: 'projectname', // Demonstration page: http://projectname.localtunnel.me
})
});
function bsReload(done) { browserSync.reload(); done(); };
// Custom Styles
gulp.task('styles', function() {
return gulp.src('app/sass/**/*.sass')
.pipe(sass({
outputStyle: 'expanded',
includePaths: [__dirname + '/node_modules']
}))
.pipe(concat('styles.min.css'))
.pipe(autoprefixer({
grid: true,
overrideBrowserslist: ['last 10 versions']
}))
.pipe(cleancss( {level: { 1: { specialComments: 0 } } })) // Optional. Comment out when debugging
.pipe(gulp.dest('app/css'))
.pipe(browserSync.stream())
});
// Scripts & JS Libraries
gulp.task('scripts', function() {
return gulp.src([
'app/lib/jquery/jquery-3.4.1.min.js',
'app/lib/lightgallery/js/lightgallery-all.js',
'app/lib/mmenu-js/mmenu.js',
'app/js/_libs.js', // JS libraries (all in one)
'app/js/_custom.js', // Custom scripts. Always at the end
])
.pipe(concat('scripts.min.js'))
.pipe(uglify()) // Minify js (opt.)
.pipe(gulp.dest('app/js'))
.pipe(browserSync.reload({ stream: true }))
});
// Responsive Images
var quality = 95; // Responsive images quality
// Produce @1x images
gulp.task('img-responsive-1x', async function() {
return gulp.src('app/img/_src/**/*.{png,jpg,jpeg,webp,raw}')
.pipe(newer('app/img/@1x'))
.pipe(responsive({
'**/*': { width: '50%', quality: quality }
})).on('error', function (e) { console.log(e) })
.pipe(rename(function (path) {path.extname = path.extname.replace('jpeg', 'jpg')}))
.pipe(gulp.dest('app/img/@1x'))
});
// Produce @2x images
gulp.task('img-responsive-2x', async function() {
return gulp.src('app/img/_src/**/*.{png,jpg,jpeg,webp,raw}')
.pipe(newer('app/img/@2x'))
.pipe(responsive({
'**/*': { width: '100%', quality: quality }
})).on('error', function (e) { console.log(e) })
.pipe(rename(function (path) {path.extname = path.extname.replace('jpeg', 'jpg')}))
.pipe(gulp.dest('app/img/@2x'))
});
gulp.task('img', gulp.series('img-responsive-1x', 'img-responsive-2x', bsReload));
// Clean @*x IMG's
gulp.task('cleanimg', function() {
return del(['app/img/@*'], { force: true })
});
// Code & Reload
gulp.task('code', function() {
return gulp.src('app/**/*.html')
.pipe(browserSync.reload({ stream: true }))
});
// Deploy
gulp.task('rsync', function() {
return gulp.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
}))
});
gulp.task('watch', function() {
gulp.watch('app/sass/**/*.sass', gulp.parallel('styles'));
gulp.watch(['app/js/_custom.js', 'app/js/_libs.js'], gulp.parallel('scripts'));
gulp.watch('app/*.html', gulp.parallel('code'));
gulp.watch('app/img/_src/**/*', gulp.parallel('img'));
});
gulp.task('removedist', function() {
return del(['dist']);
});
gulp.task('dist', function () {
var buildFiles = gulp.src([
'app/*.html',
]).pipe(gulp.dest('dist'));
var buildCss = gulp.src([
'app/css/styles.min.css',
]).pipe(gulp.dest('dist/css'));
var buildJs = gulp.src([
'app/js/scripts.min.js',
]).pipe(gulp.dest('dist/js'));
var buildFonts = gulp.src([
'app/fonts/**/*',
]).pipe(gulp.dest('dist/fonts'));
var buildImage = gulp.src([
'app/img/**/*',
]).pipe(gulp.dest('dist/img'));
return buildFiles, buildCss, buildJs, buildFonts, buildImage;
});
gulp.task('default', gulp.parallel('img', 'styles', 'scripts', 'browser-sync', 'watch'));
gulp.task('build', gulp.series('removedist','styles', 'scripts', 'img', 'dist'));