-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·134 lines (117 loc) · 4.19 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
var syntax = 'sass', // Syntax: sass or scss;
gulpVersion = '4'; // Gulp version: 3 or 4
gmWatch = false; // ON/OFF GraphicsMagick watching "img/_src" folder (true/false). Linux install gm: sudo apt update; sudo apt install graphicsmagick
var gulp = require('gulp'),
gutil = require('gulp-util' ),
sass = require('gulp-sass'),
browserSync = require('browser-sync'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
cleancss = require('gulp-clean-css'),
rename = require('gulp-rename'),
autoprefixer = require('gulp-autoprefixer'),
notify = require('gulp-notify'),
rsync = require('gulp-rsync'),
imageResize = require('gulp-image-resize'),
imagemin = require('gulp-imagemin'),
del = require('del');
// Local Server
gulp.task('browser-sync', function() {
browserSync({
server: {
baseDir: 'app'
},
notify: false,
open: false,
// online: false, // Work Offline Without Internet Connection
// tunnel: true, tunnel: "projectname", // Demonstration page: http://projectname.localtunnel.me
})
});
// Sass|Scss Styles
gulp.task('styles', function() {
return gulp.src('app/'+syntax+'/**/*.'+syntax+'')
.pipe(sass({ outputStyle: 'expanded' }).on("error", notify.onError()))
.pipe(rename({ suffix: '.min', prefix : '' }))
.pipe(autoprefixer(['last 15 versions']))
.pipe(cleancss( {level: { 1: { specialComments: 0 } } })) // Opt., comment out when debugging
.pipe(gulp.dest('app/css'))
.pipe(browserSync.stream())
});
// JS
gulp.task('scripts', function() {
return gulp.src([
'app/libs/jquery/dist/jquery.min.js',
'app/libs/maskedinput/jquery.maskedinput.min.js',
'app/libs/slick/slick.min.js',
'app/libs/selectric/jquery.selectric.min.js',
'app/js/common.js', // Always at the end
])
.pipe(concat('scripts.min.js'))
// .pipe(uglify()) // Mifify js (opt.)
.pipe(gulp.dest('app/js'))
.pipe(browserSync.reload({ stream: true }))
});
// HTML Live 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'], // Includes files to deploy
exclude: ['**/Thumbs.db', '**/*.DS_Store'], // Excludes files from deploy
recursive: true,
archive: true,
silent: false,
compress: true
}))
});
// Images @x1 & @x2 + Compression | Required graphicsmagick (sudo apt update; sudo apt install graphicsmagick)
gulp.task('img1x', function() {
return gulp.src('app/img/_src/**/*.*')
.pipe(imageResize({ width: '50%' }))
.pipe(imagemin())
.pipe(gulp.dest('app/img/@1x/'))
});
gulp.task('img2x', function() {
return gulp.src('app/img/_src/**/*.*')
.pipe(imageResize({ width: '100%' }))
.pipe(imagemin())
.pipe(gulp.dest('app/img/@2x/'))
});
// Clean @*x IMG's
gulp.task('cleanimg', function() {
return del(['app/img/@*'], { force:true })
});
// If Gulp Version 3
if (gulpVersion == 3) {
// Img Processing Task for Gulp 3
gulp.task('img', ['img1x', 'img2x']);
var taskArr = ['styles', 'scripts', 'browser-sync'];
gmWatch && taskArr.unshift('img');
gulp.task('watch', taskArr, function() {
gulp.watch('app/'+syntax+'/**/*.'+syntax+'', ['styles']);
gulp.watch(['libs/**/*.js', 'app/js/common.js'], ['scripts']);
gulp.watch('app/*.html', ['code']);
gmWatch && gulp.watch('app/img/_src/**/*', ['img']);
});
gulp.task('default', ['watch']);
};
// If Gulp Version 4
if (gulpVersion == 4) {
// Img Processing Task for Gulp 4
gulp.task('img', gulp.parallel('img1x', 'img2x'));
gulp.task('watch', function() {
gulp.watch('app/'+syntax+'/**/*.'+syntax+'', gulp.parallel('styles'));
gulp.watch(['libs/**/*.js', 'app/js/common.js'], gulp.parallel('scripts'));
gulp.watch('app/*.html', gulp.parallel('code'));
gmWatch && gulp.watch('app/img/_src/**/*', gulp.parallel('img')); // GraphicsMagick watching image sources if allowed.
});
gmWatch ? gulp.task('default', gulp.parallel('img', 'styles', 'scripts', 'browser-sync', 'watch'))
: gulp.task('default', gulp.parallel('styles', 'scripts', 'browser-sync', 'watch'));
};