-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
138 lines (122 loc) · 3.59 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
const gulp = require('gulp');
const buffer = require('vinyl-buffer');
const postcss = require('gulp-postcss');
const sass = require('gulp-sass');
const csso = require('gulp-csso');
const autoprefixer = require('autoprefixer');
const browserSync = require('browser-sync').create();
const gulpIf = require('gulp-if');
const sourcemaps = require('gulp-sourcemaps');
const svgSymbols = require('gulp-svg-symbols');
const svgmin = require('gulp-svgmin');
const rename = require('gulp-rename');
const del = require('del');
const gutil = require('gulp-util');
const pug = require('gulp-pug');
const spritesmith = require('gulp.spritesmith');
const tinypng = require('gulp-tinypng-nokey');
const bro = require('gulp-bro');
const babelify = require('babelify');
const uglify = require('gulp-uglify');
const isDevelopment = process.env.NODE_ENV !== 'production';
sass.compiler = require('node-sass');
gulp.task('views', function buildHTML() {
return gulp.src('./src/index.pug')
.pipe(pug())
.on('error', function(error) {
gutil.log(gutil.colors.red('Error: ' + error.message));
this.emit('end');
})
.pipe(gulp.dest('./public'));
});
gulp.task('styles', function () {
return gulp.src('./src/app.scss')
.pipe(gulpIf(isDevelopment, sourcemaps.init()))
.pipe(sass().on('error', sass.logError))
.pipe(gulpIf(!isDevelopment, postcss([
autoprefixer({
browsers: ['> 5%', 'ff > 14']
})
])))
.pipe(gulpIf(!isDevelopment, csso()))
.pipe(rename('style.css'))
.pipe(gulpIf(isDevelopment, sourcemaps.write()))
.pipe(gulp.dest('./public/css'));
});
gulp.task('scripts', function () {
return gulp.src('./src/app.js')
.pipe(bro({
debug: isDevelopment,
transform: [ babelify ]
}))
.pipe(gulpIf(!isDevelopment, uglify()))
.pipe(rename('bundle.js'))
.pipe(gulp.dest('./public/js'));
});
gulp.task('fonts', function () {
return gulp.src([
'./src/fonts/**/*.*',
'./node_modules/font-awesome/fonts/**/*.*'
])
.pipe(gulp.dest('./public/fonts'));
});
gulp.task('images', function () {
return gulp.src(['./src/images/**/*.*', '!./src/images/sprite/*.*'])
.pipe(gulpIf(!isDevelopment, tinypng()))
.pipe(gulp.dest('./public/images'));
});
gulp.task('svgSymbols', function () {
return gulp.src('./src/assets/images/svg/**/*.svg')
.pipe(svgmin({
plugins: [{
removeViewBox: false
}]
}))
.pipe(svgSymbols({
templates: ['default-svg'],
class: '.icon_%f'
}))
.pipe(gulp.dest('./public'));
});
gulp.task('misc', function () {
return gulp.src('./src/assets/misc/**/*.*')
.pipe(gulp.dest('./public'));
});
gulp.task('db', function () {
return gulp.src('./src/db/**/*.json')
.pipe(gulp.dest('./public/db'));
});
gulp.task('watch', function () {
gulp.watch('./src/db/*.json', gulp.series('db'));
gulp.watch('./src/**/*.pug', gulp.series('views'));
gulp.watch('./src/**/*.js', gulp.series('scripts'));
gulp.watch('./src/**/*.{css,scss}', gulp.series('styles'));
gulp.watch('./src/assets/images/**/*.*', gulp.series('images'));
gulp.watch('./src/assets/images/svg/**/*.svg', gulp.series('svgSymbols'));
});
gulp.task('serve', function () {
browserSync.init({
server: './public',
port: 8080
});
browserSync.watch('./public/**/*.*').on('change', browserSync.reload);
});
gulp.task('clean', function () {
return del('./public')
});
gulp.task('build', gulp.series(
'clean',
'svgSymbols',
gulp.parallel(
'views',
'styles',
'scripts',
'fonts',
'images'
)));
gulp.task('default', gulp.series(
'build',
gulp.parallel(
'watch',
'serve'
)));