-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
141 lines (132 loc) · 3.52 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
var paths = {
sync: {
proxy: 'wordpress.test',
delay: 2000
},
styles: {
src: 'dev/styles/**/*.scss',
dest: 'dist/styles'
},
scripts: {
src: 'dev/scripts/**/*.js',
dest: 'dist/scripts'
},
icons: {
src: 'assets/icons/*.svg',
template: 'dev/templates/icons.css',
dest: 'dist/icons/'
}
};
var gulp = require('gulp');
var log = require('fancy-log');
var sourcemaps = require('gulp-sourcemaps');
var sass = require('gulp-sass');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var cssnano = require('cssnano');
var uglify = require('gulp-uglify');
var eslint = require('gulp-eslint');
var iconfont = require('gulp-iconfont');
var iconfontCss = require('gulp-iconfont-css');
var notify = require('gulp-notify');
var browserSync = require('browser-sync').create();
var clear = require('console-clear');
function styles(done) {
clear(true);
log.info('Starting styles!');
return (
gulp
.src(paths.styles.src)
.pipe(sourcemaps.init())
.pipe(sass())
.on('error', notify.onError({
message: 'Error: <%= error.message %>',
title: 'Styles error!'
}))
.pipe(postcss([autoprefixer(), cssnano()]))
.pipe(sourcemaps.write('.'))
.pipe( gulp.dest(paths.styles.dest) )
.pipe(browserSync.stream())
.pipe(notify('Complete styles!'))
);
done();
}
exports.styles = styles;
function scripts(done) {
clear(true);
log.info('Starting scripts!');
return (
gulp
.src(paths.scripts.src)
.pipe(eslint({
'rules':{
'quotes': [1, 'single'],
'semi': [1, 'always']
}
}))
.pipe(eslint.format())
.pipe(eslint.failAfterError())
.on('error', function(){
notify.onError({
message: 'Error: <%= error.message %>',
title: 'Scripts error!'
});
done();
})
.pipe( uglify() )
.pipe( gulp.dest(paths.scripts.dest) )
.pipe(browserSync.stream())
.pipe(notify('Complete scripts!'))
);
done();
}
exports.scripts = scripts;
function icons(done) {
clear(true);
log.info('Starting icons!');
return (
gulp
.src(paths.icons.src)
.pipe( iconfontCss({
fontName: 'icons',
path: paths.icons.template,
targetPath: 'icons.css',
fontPath: ''
}) )
.pipe( iconfont({
fontName: 'icons',
normalize: true,
fontHeight: 1001,
prependUnicode: true,
formats: ['ttf', 'eot', 'woff'],
timestamp: Math.round(Date.now()/1000)
}) )
.pipe( gulp.dest(paths.icons.dest) )
.pipe(browserSync.stream())
.pipe(notify('Complete icons!'))
);
done();
}
exports.icons = icons;
function serve(){
clear(true);
browserSync.init({
proxy: paths.sync.proxy,
reloadDelay: paths.sync.delay
});
watch();
gulp.watch("*.php").on('change', browserSync.reload);
}
exports.serve = serve;
function watch(){
log.info('Starting watch!');
gulp.watch(paths.styles.src, gulp.series('styles'));
gulp.watch(paths.scripts.src, gulp.series('scripts'));
gulp.watch(paths.icons.src, gulp.series('icons'));
}
exports.watch = watch;
exports.build = gulp.parallel(scripts, styles, icons);
function start(){
watch();
}
exports.default = start;