-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
195 lines (182 loc) · 4.61 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
var gulp = require('gulp'),
sass = require('gulp-sass'),
browserSync = require('browser-sync'),
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'),
svgmin = require('gulp-svgmin'),
webp = require('gulp-webp');
// Local Server
gulp.task('browser-sync', function () {
browserSync({
server: {
baseDir: 'app'
},
notify: false,
// online: false, // Work offline without internet connection
// tunnel: 'vsevolod',
// Demonstration page: http://vsevolod.localtunnel.me
})
});
function bsReload(done) {
browserSync.reload();
done();
};
// Custom Styles
gulp.task('styles', function () {
return gulp.src('app/sass/**/*.sass')
.pipe(sass({
outputStyle: 'expanded'
}))
.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([
// 'node_modules/jquery/dist/jquery.min.js', // Optional jQuery plug-in (npm i --save-dev jquery)
'app/js/_lazy.js', // JS library plug-in example
'app/js/_custom.js', // Custom scripts. Always at the end
])
.pipe(concat('scripts.min.js'))
.pipe(uglify()) // Mifify js (opt.)
.pipe(gulp.dest('app/js'))
.pipe(browserSync.reload({
stream: true
}))
});
//SVG
gulp.task('svg', async function () {
return gulp.src('app/img/_src/*.svg', {allowEmpty: true})
.pipe(newer('app/img/svg'))
.pipe(svgmin({
plugins: [
{
convertPathData: {
floatPrecision: 2
}
},
{
cleanupListOfValues: {
floatPrecision: 2
}
},
{
removeViewBox: {
active: false
}
},
{
removeDimensions: {
active: true
}
},
{
sortAttrs: {
active: true
}
}
],
js2svg: {
// pretty: true
}
}))
.pipe(gulp.dest('app/img/svg/'));
});
// Responsive Images
gulp.task('img-responsive', async function () {
return gulp.src('app/img/_src/**/*.{png,jpg,jpeg,raw}')
.pipe(newer({dest: 'app/img/@1x', ext: '.webp'}))
.pipe(webp())
.pipe(responsive({
'*': [{
// Produce @2x images
width: '100%',
quality: 90,
rename: {
prefix: '@2x/',
},
}, {
// Produce @1x images
width: '50%',
quality: 90,
rename: {
prefix: '@1x/',
}
}]
})).on('error', function () {
console.log('No matching images found')
})
.pipe(rename(function (path) {
path.extname = path.extname.replace('jpeg', 'jpg')
}))
.pipe(gulp.dest('app/img'))
});
gulp.task('img', gulp.series(gulp.parallel('img-responsive', 'svg'), bsReload));
// Clean @*x IMG's
gulp.task('cleanimg', function () {
return del(['app/img/@*', 'app/img/svg'], {
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
}))
});
//Remove dist folder
gulp.task('removedist', gulp.series(function(done) {
del.sync('dist');
done();
}));
//Build
gulp.task('build', gulp.series('removedist', 'img', 'styles', 'scripts', function transferAll(done) {
gulp.src(['app/*.html', 'app/.htaccess',], { allowEmpty: true }).pipe(gulp.dest('dist'));
gulp.src('app/css/styles.min.css', { allowEmpty: true }).pipe(gulp.dest('dist/css'));
gulp.src('app/js/scripts.min.js', { allowEmpty: true }).pipe(gulp.dest('dist/js'));
gulp.src('app/fonts/*.woff2', { allowEmpty: true }).pipe(gulp.dest('dist/fonts'));
gulp.src('app/img/!(_*)/*', { allowEmpty: true }).pipe(gulp.dest('dist/img'));
done();
}));
gulp.task('watch', function () {
gulp.watch('app/sass/**/*.sass', gulp.parallel('styles'));
gulp.watch(['libs/**/*.js', 'app/js/_custom.js'], gulp.parallel('scripts'));
gulp.watch('app/*.html', gulp.parallel('code'));
gulp.watch('app/img/_src/**/*', gulp.parallel('img'));
});
gulp.task('default', gulp.parallel('img', 'styles', 'scripts', 'browser-sync', 'watch'));