-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
141 lines (129 loc) · 3.45 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
"use strict";
/*global require*/
const autoprefixer = require('autoprefixer');
const babel = require('gulp-babel');
const browserSync = require('browser-sync');
const changed = require('gulp-changed');
const concat = require('gulp-concat');
const del = require('del');
const gulp = require('gulp');
const gulpif = require('gulp-if');
const imagemin = require('gulp-imagemin');
const plumber = require('gulp-plumber');
const postcss = require('gulp-postcss');
const pug = require('gulp-pug');
const runSequence = require('run-sequence');
const sass = require('gulp-sass');
const uglify = require('gulp-uglify');
const html2pug = require('gulp-html2pug');
/**
* List of options
* Список опций
*/
const options = {
uglifyJS: true,
useBabel: true,
};
/*
* List of directories
* Список директорий
*/
const paths = {
input: {
sass: './src/sass/',
data: './src/_data/',
js: './src/js/',
images: './src/img/',
templates: '.src/html/public/'
},
output: {
css: './src/assets/css/',
js: './src/assets/js/',
images: './src/assets/img/'
},
public: './public/',
};
/************************
* Gulp Tasks / Задачи *
************************/
/**
* Concat all scripts and make sourcemap (optional)
* Scripts from vendor folder added first
* Объединяем все скрипты в один файл и делаем карту (опционально)
* Скрипты из папки vendor добавляются в первую очередь
*/
gulp.task('javascript', function () {
return gulp.src([paths.input.js + 'vendor/**/*.js', paths.input.js + '**/*.js'])
.pipe(plumber())
.pipe(gulpif(options.useBabel, babel({
presets: ['@babel/preset-env']
})))
.pipe(concat('script.js'))
.pipe(gulpif(options.uglifyJS, uglify()))
.pipe(gulp.dest(paths.output.js))
.pipe(browserSync.reload({
stream: true
}));
});
/*
* Minify all images
* Оптимизируем изображения
*/
gulp.task('image-min', function () {
return gulp.src(paths.input.images + '**/*.+(png|jpg|gif|svg|jpeg)')
.pipe(plumber())
.pipe(changed(paths.output.images))
.pipe(imagemin())
.pipe(gulp.dest(paths.output.images));
});
// Specific task for backend only solution
gulp.task('pug-prod', function () {
return gulp.src('./src/html/templates/**/*.pug')
.pipe(plumber())
.pipe(pug({pretty: true}))
.pipe(html2pug())
.pipe(gulp.dest(paths.public + '/views/'))
.pipe(browserSync.reload({
stream: true
}));
});
/**
* Removing public folder with it contents
* Удаляем папку public со всем ее содержимым
*/
gulp.task('build-clean', function () {
return del(paths.public);
});
/**
* Building distributive
* Создаем дистрибутив
*/
gulp.task('build-dist', function () {
runSequence('build-clean',
['sass', 'javascript', 'image-min', 'pug-prod']);
});
/**
* Compile .scss files
* Autoprefixer
* Sourcemaps (optional)
* Компилируем файлы .scss
* Используем Autoprefixer для добавления вендорных префиксов
* Создаем карты (опционально)
*/
gulp.task('sass', function () {
return gulp.src(paths.input.sass + '*.scss')
.pipe(plumber())
.pipe(sass({
includePaths: [paths.input.sass],
outputStyle: 'compressed'
}))
.pipe(postcss([autoprefixer()]))
.pipe(gulp.dest(paths.output.css))
.pipe(browserSync.reload({
stream: true
}));
});
/**
* Shorthand for build-dist
*/
gulp.task('build', ['build-dist']);