-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
79 lines (63 loc) · 2.18 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
'use strict';
const gulp = require("gulp");
const del = require('del');
const run = require('run-sequence');
const browserSync = require("browser-sync").create();
const isDevelopment = !process.env.NODE_ENV || process. s == 'development';
function lazyRequireTask(taskName, path, options) {
options = options || {};
options.taskName = taskName;
gulp.task(taskName, function (callback) {
let task = require(path).call(this, options);
return task(callback);
});
}
lazyRequireTask('styles', './tasks/styles.js', {
src: 'frontend/styles/style.css'
});
lazyRequireTask('assets', './tasks/assets.js', {
src: 'frontend/assets/**'
});
lazyRequireTask('styles:assets', './tasks/styles_assets.js', {
src: 'frontend/assets/**/*.{png,jpg,svg}'
});
lazyRequireTask('webp', './tasks/webp.js', {
src: 'frontend/assets/**/*.{png,jpg}'
});
lazyRequireTask('styles:svg', './tasks/styles_svg.js', {
src: 'frontend/assets/**/icon-*.svg'
});
gulp.task('clean', function () {
return del('public');
});
lazyRequireTask('lint', './tasks/lint.js', {
src: 'frontend/**/*.js'
});
lazyRequireTask('inlineSvgToHtml', './tasks/inlineSvgToHtml.js', {
src: 'frontend/**/*.html'
});
lazyRequireTask('assets', './tasks/assets.js', {
src: 'frontend/assets/fonts/*.*'
});
gulp.task('watch',function () {
gulp.watch('frontend/styles/**/*.*',['styles']);
gulp.watch('frontend/styles/**/*.{png,jpg,svg}', ['styles:assets']);
gulp.watch('frontend/styles/**/*.{png,jpg}', ['webp']);
gulp.watch('frontend/styles/**/icon-*.svg', ['styles:svg']);
gulp.watch('public/styles/**/sprite.svg', ['inlineSvgToHtml']);
gulp.watch('frontend/**/*.html', ['inlineSvgToHtml']);
gulp.watch('frontend/assets/fonts/*.*', ['assets']);
});
gulp.task('dev', function (callback) {
run('build', ['watch', 'serve',], callback)
});
gulp.task('build', function (callback) {
run('clean', 'styles:svg', ['inlineSvgToHtml', 'styles', 'styles:assets', 'webp', 'assets'], callback);
});
gulp.task('default', ['build']);
gulp.task("serve", function () {
browserSync.init({
server: 'public'
});
browserSync.watch('public/**/*.*').on('change', browserSync.reload);
});