-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgulpfile.js
110 lines (98 loc) · 2.88 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
const gulp = require('gulp');
const gulpConnect = require('gulp-connect');
const gulpUglify = require('gulp-uglify');
const gulpPug = require('gulp-pug');
const gulpImageMin = require('gulp-imagemin');
const gulpData = require('gulp-data');
const gulpStylus = require('gulp-stylus');
const gulpif = require('gulp-if');
const gulpCleanCSS = require('gulp-clean-css');
const plumber = require('gulp-plumber');
const del = require('delete');
const svgSprite = require('gulp-svg-sprite');
const outputDir = 'static';
const isProduction = process.env.NODE_ENV === 'production';
const srcStylus = ['src/**/*.css', 'src/**/*.styl'];
const srcPug = 'src/**/*.pug';
const srcJS = 'src/**/*.js';
const srcSVG = 'src/assets/*.svg';
const srcImages = ['src/**/*.svg', 'src/**/*.jpg', 'src/**/*.gif', 'src/**/*.png'];
function server() {
return gulpConnect.server({
host: '0.0.0.0',
port: 8080,
root: 'static/',
livereload: true
});
}
function clean(cb) {
del([outputDir], cb);
}
function stylus() {
return gulp.src(srcStylus)
.pipe(gulpStylus({
'include css': true
}))
.pipe(gulpCleanCSS())
.pipe(gulp.dest(outputDir))
.pipe(gulpif(!isProduction, gulpConnect.reload()));
}
function svg() {
return gulp.src(srcSVG, { cwd: '' })
.pipe(plumber())
.pipe(svgSprite({
mode: {
css: {
render: {
css: true
}
}
}
}))
.on('error', function(error) {
console.log(error)
})
.pipe(gulp.dest(outputDir));
}
function pug() {
return gulp.src(srcPug)
.pipe(gulpData(() => {
return {
__dirname: __dirname,
require: require
};
}))
.pipe(gulpPug())
.pipe(gulp.dest(outputDir))
.pipe(gulpif(!isProduction, gulpConnect.reload()));
}
function images() {
return gulp.src(srcImages)
.pipe(gulpif(isProduction, gulpImageMin()))
.pipe(gulp.dest(outputDir))
.pipe(gulpif(!isProduction, gulpConnect.reload()));
}
function js() {
return gulp.src(srcJS)
.pipe(gulpif(isProduction, gulpUglify()))
.pipe(gulp.dest(outputDir))
.pipe(gulpif(!isProduction, gulpConnect.reload()));
}
function watch() {
gulp.watch(srcJS, gulp.series(js));
gulp.watch(srcSVG, gulp.series(svg));
gulp.watch(srcStylus, gulp.series(stylus));
gulp.watch(srcImages, gulp.series(images));
gulp.watch(srcPug, gulp.series(pug));
}
exports.default = gulp.parallel(
watch,
gulp.series(clean, js, svg, pug, stylus, images, server)
);
exports.server = server;
exports.clean = clean;
exports.build = gulp.series(clean, js, svg, pug, images, stylus);
exports.dev = gulp.parallel(
watch,
gulp.series(clean, js, pug, svg, stylus, images, server)
);