-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
189 lines (147 loc) · 6.19 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
"use strict";
const gulp = require('gulp'),
browserSync = require('browser-sync');
let Src = { Path: './src/' }; // Path to source project files
Src.Spr = Src.Path + 'img/Sprites/'; // Path to sprites files
Src.SprSrc = Src.Spr + 'SrcSprites/'; // Path to source sprites files
Src.Sass = Src.Path + 'sass/'; // Path to source sass files
Src.Html = Src.Path + '**/*.html'; // Path to source Html files
Src.Fonts = Src.Path + 'fonts/**'; // Path to source fonts files
Src.Css = Src.Path + 'css/'; // Path to source css files
Src.Img = Src.Path + 'img/'; // Path to source images files
Src.Js = Src.Path + 'js/'; // Path to source JS files
let Pub = { Path: './dist/' }; // Path to build files
Pub.Js = Pub.Path + 'js/'; // Path to build js files
Pub.Css = Pub.Path + 'css/'; // Path to build css files
Pub.Img = Pub.Path + 'img/'; // Path to build img files
function requireTask(taskName, path, options) {
options = options || {};
options.taskName = taskName;
gulp.task(taskName, (callback) => {
let task = require(path).call(this, options);
return task(callback);
});
}
// It's make big svg atlas with .scss rules from many single svg files.
requireTask('sprite:svg', './tasks/spritesvg', {
src: Src.SprSrc + 'Svg/*.svg',
dest: Src.SprSrc + 'Svg/tmp/',
svg: Src.SprSrc + 'Svg/tmp/*.svg',
img: Src.Spr
});
// It's make big png atlas with .scss rules from many single png files.
requireTask('sprite:png', './tasks/spritepng', {
src: Src.Path + 'sass/sprite.png',
dest: Src.Spr,
srcSpr: Src.SprSrc + 'Png/**/*.png',
destSpr: Src.Path + 'Sass/',
imgPath: Src.Spr + 'sprite.png'
});
// It's using for start server with autoreload on changes.
requireTask('server', './tasks/server', {
dir: 'src/',
port: 8550
});
// Needed to transform JS files with new ES standards for old browsers with support ES 2015.
// Also making possible to using modules in JS code.
requireTask('browserify', './tasks/browserify', {
src: Src.Js + 'app.js',
dest: Src.Js,
map: 'main.js'
});
// Minify JS files.
requireTask('uglify', './tasks/uglify', {
src: Src.Js + 'main.js',
suffix: '.min',
dest: Src.Js
});
// It's needed for compress all images files and move them to '/dist' directory.
requireTask('imgOptimize', './tasks/imgOptimize', {
src: Src.Img + '**/*.{png, gif, svg}',
srcMove: Src.Img + 'Sprites/*.svg',
filt: ['!' + Src.Img + 'Sprites/SrcSprites/**/*.*', '!' + Src.Img + 'Sprites/*.svg'],
base: Src.Img,
dest: Pub.Img,
srcJpg: Src.Img + '**/*.{jpg,jpeg}'
});
// Just minify all css files.
requireTask('minify', './tasks/minify', {
src: [Src.Css + '*.css', '!' + Src.Css + '*.min.css'],
dest: Src.Css,
suffix: ".min"
});
// Delete directory 'dist'
requireTask('clean', './tasks/clean', {
src: Pub.Path
});
// It's necessary for transfer all ready files in public/dist directory.
requireTask('Trans', './tasks/Trans', {
src: [
Src.Fonts,
Src.Html,
Src.Js + 'main.min.{js,js.map}',
Src.Path + 'libs/*.min.*'
],
dest: Pub.Path,
base: Src.Path
});
// It's needed for clear all unused in html files css selectors.
requireTask('uncss', './tasks/uncss', {
src: [Src.Css + '*.css','!' + Src.Css + '*.min.css'],
dest: Pub.Css,
base: Src.Css,
html: Src.Html,
suffix: ".min"
});
// Bower is deprecated.
/*
requireTask('bower', './tasks/bower', {
dest: Src.Path + 'libs',
fonts: Src.Path + 'Fonts/',
suffix: '.min'
});
*/
// It's necessary to get all the .сss files in src/libs/src/css directory and merge it in one compressed file.
// Compressed file is located in src/libs/libs.min.css.
requireTask('libscss', './tasks/libscss', {
dest: Src.Path + 'libs/',
suffix: '.min',
css: Src.Path + 'libs/src/css/'
});
// It's necessary to get all the .js files in src/libs/src/js directory and merge it in one compressed file.
// Compressed file is located in src/libs/libs.min.js.
requireTask('libsjs', './tasks/libsjs', {
dest: Src.Path + 'libs/',
suffix: '.min',
js: Src.Path + 'libs/src/js/'
});
// Clearing all saved cache for files, which using in tasks.
requireTask('clearcached', './tasks/clearcached', {});
// Needed for compiling .pug files into .html files.
requireTask('pug', './tasks/pug', {
src: Src.Path + 'Pug/*.pug',
dest: Src.Path
});
// Needed for compiling .scss files into .css files.
requireTask('sass', './tasks/sass', {
src: Src.Sass + 'main.scss',
dest: Src.Css
});
gulp.task('preload', gulp.series('sass','minify', 'browserify','uglify'));
gulp.task('build', gulp.series('clean', 'sass', 'pug', 'libsjs', 'libscss', 'uncss', 'imgOptimize', 'browserify', 'uglify', 'Trans'));
gulp.task('watch', () => {
gulp.watch(Src.Sass + '**/*.scss', gulp.series('sass','minify'));
gulp.watch(Src.Css + '*.css').on('change', browserSync.reload);
gulp.watch(Src.Path + 'libs/src/css/**/*.css', gulp.series('libscss')).on('change', browserSync.reload);
gulp.watch(Src.Path + 'libs/src/js/**/*.js', gulp.series('libsjs')).on('change', browserSync.reload);
gulp.watch(Src.Html).on('change', browserSync.reload);
gulp.watch(Src.Img).on('change', browserSync.reload);
gulp.watch(Src.SprSrc + 'Svg/*.svg', gulp.series('sprite:svg')).on('change', browserSync.reload);
gulp.watch(Src.SprSrc + 'Png/*.png', gulp.series('sprite:png')).on('change', browserSync.reload);
gulp.watch(Src.Path + 'pug/**/*.pug', gulp.series('pug'));
gulp.watch([Src.Js + 'modules/**/*.js', Src.Js + 'app.js'], gulp.series('browserify'));
gulp.watch(Src.Js + 'main.js', gulp.series('uglify'));
gulp.watch(Src.Js + 'main.min.js').on('change', browserSync.reload);
// gulp.watch('./bower.json', gulp.series('bower')).on('change', browserSync.reload);
});
gulp.task('default', gulp.parallel('server','watch'));