This repository was archived by the owner on Oct 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgulpfile.js
93 lines (83 loc) · 2.46 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
'use strict';
const gulp = require('gulp');
const terser = require('gulp-terser');
const postcss = require('gulp-postcss');
const postcssrc = require('postcss-load-config');
const concat = require('gulp-concat');
const sass = require('gulp-sass');
const pug = require('gulp-pug');
const plumber = require('gulp-plumber');
const wait = require('gulp-wait');
const linter = { pug: require('gulp-pug-linter') };
gulp.task('build-js', () =>
gulp
.src('src/js/**/*.js')
.pipe(concat('knzkapp.min.js'))
.pipe(terser())
.on('error', err => {
// eslint-disable-next-line no-console
console.error(err);
})
.pipe(gulp.dest('www/'))
);
gulp.task('dev-build-js', () =>
gulp
.src('src/js/**/*.js')
.pipe(
plumber({
errorHandler(err) {
// eslint-disable-next-line no-console
console.log(err.messageFormatted);
this.emit('end');
}
})
)
.pipe(concat('knzkapp.min.js'))
.pipe(gulp.dest('www/'))
);
gulp.task('build-scss', () => {
return postcssrc().then(config => {
return gulp
.src('src/scss/style.scss')
.pipe(
plumber({
errorHandler(err) {
// eslint-disable-next-line no-console
console.log(err.messageFormatted);
this.emit('end');
}
})
)
.pipe(wait(100))
.pipe(sass())
.pipe(postcss(config.plugins, config.options))
.pipe(concat('knzkapp.min.css'))
.pipe(gulp.dest('www/'));
});
});
gulp.task('build-pug', () =>
gulp
.src('src/pug/index.pug')
.pipe(pug())
.pipe(concat('index.html'))
.pipe(gulp.dest('www/'))
);
gulp.task('build', gulp.parallel('build-js', 'build-scss', 'build-pug'));
gulp.task('watch', () => {
const watcher = gulp.watch('src/scss/**/*.scss', gulp.parallel('build-scss'));
watcher.on('change', evt => {
// eslint-disable-next-line no-console
console.log(`file: ${evt.path}, type: ${evt.type}`);
});
const watcherJS = gulp.watch('src/js/**/*.js', gulp.parallel('dev-build-js'));
watcherJS.on('change', evt => {
// eslint-disable-next-line no-console
console.log(`file: ${evt.path}, type: ${evt.type}`);
});
const watcherPug = gulp.watch('src/pug/**/*.pug', gulp.parallel('build-pug'));
watcherPug.on('change', evt => {
// eslint-disable-next-line no-console
console.log(`file: ${evt.path}, type: ${evt.type}`);
});
});
gulp.task('lint-pug', () => gulp.src('src/pug/**/*.pug').pipe(linter.pug()));