-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
150 lines (136 loc) · 4 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
'use strict';
var basedir = 'www',
del = require('del'),
gulp = require('gulp'),
gulpLoadPlugins = require('gulp-load-plugins'),
plugins = gulpLoadPlugins(),
imageminPngquant = require('imagemin-pngquant'),
runSequence = require('run-sequence');
var path = {
src: { // Ïóòè îòêóäà áðàòü èñõîäíèêè
js: basedir+ '/javascript/src',
css: basedir+ '/css/src',
img: basedir+ '/images/src',
fonts: basedir+ '/fonts'
},
out: { // Òóò ìû óêàæåì êóäà ñêëàäûâàòü
js: basedir+ '/javascript',
css: basedir+ '/css',
img: basedir+ '/images',
fonts: basedir+ '/fonts'
}
};
//--------------------------------------------------------------
// TASKS
//--------------------------------------------------------------
// Compile CSS
gulp.task('compile:css', function(){
return gulp.src( path.src.css + '/*.css' )
.pipe(plugins.convertEncoding({to: 'UTF-8'}))
.pipe(plugins.autoprefixer({
browsers: [
'> 1%',
'last 2 versions',
'firefox >= 4',
'safari 7',
'safari 8',
'IE 8',
'IE 9',
'IE 10',
'IE 11'
], cascade: false })
)
.pipe(plugins.concat('style.css'))
.pipe(plugins.convertEncoding({to: 'Windows-1251'}))
.pipe(gulp.dest( path.out.css ))
.pipe(plugins.livereload());
});
// Concat vendor CSS
gulp.task('compile-vendor:css', function() {
return gulp.src([
path.src.css + '/vendor/**/*.css',
'!'+path.src.css+'/vendor/**/*.min.css',
'!'+path.src.css+'/vendor/**/*-min.css'
])
.pipe(plugins.concat('vendor.css'))
.pipe(gulp.dest( path.out.css ));
});
// Minify CSS
gulp.task('minify:css', function() {
return gulp.src([
path.out.css + '/*.css',
'!'+path.out.css+'/*.min.css',
'!'+path.out.css+'/*-min.css'
])
.pipe(plugins.minifyCss())
.pipe(plugins.rename({ suffix: '.min' }))
.pipe(gulp.dest( path.out.css ));
});
// Compile JS
gulp.task('compile:js', function() {
return gulp.src( [
path.src.js + '/*.js'
])
.pipe(plugins.concat('common.js'))
.pipe(gulp.dest( path.out.js ))
.pipe(plugins.livereload());
});
// Concat vendor JS
gulp.task('compile-vendor:js', function() {
return gulp.src( [
path.src.js + '/vendor/**/*.js',
'!'+path.src.js + '/vendor/jquery/jquery-*.js', // Exclude Jquery
'!'+path.src.js + '/vendor/material/*.js', // Exclude Material
])
.pipe(plugins.concat('vendor.js'))
.pipe(gulp.dest( path.out.js ))
.pipe(plugins.livereload());
});
// Minify JS
gulp.task('minify:js', function() {
return gulp.src([
path.out.js + '/common.js',
path.out.js + '/vendor.js'
])
.pipe(plugins.uglify())
.pipe(plugins.rename({ suffix: '.min' }))
.pipe(gulp.dest( path.out.js ));
});
// Minify pictures
gulp.task('minify:images', function() {
return gulp.src( path.src.img + '/**/*.{jpg,gif,png}' )
.pipe(plugins.imagemin({
progressive: true,
use: [imageminPngquant({ quality: '65-80', speed: 4 })]
}))
.pipe(gulp.dest(path.out.img));
});
// Clean
gulp.task('clean', function () {
return del([
// Delete CSS
path.out.css + '/style.css',
path.out.css + '/style.min.css',
path.out.css + '/vendor.css',
path.out.css + '/vendor.min.css',
// Delete JS
path.out.js + '/common.js',
path.out.js + '/common.min.js'
]);
});
// Builder
gulp.task('build', function(cb) {
// runSequence ïîçâîëÿåò çàïóñêàòü çàäà÷è ïî ïîðÿäêó
runSequence('clean', // 1
['compile:css', 'compile-vendor:css', 'compile:js', 'compile-vendor:js'], // 2 (òàñêè âûïîëíÿòñÿ âïàðàëëåëü)
['minify:css', 'minify:js', 'minify:images'] // 3
);
});
// Watcher
gulp.task('default', function(){
plugins.livereload.listen();
// Îïîâåùàåì Livereload îá èçìåíåíèÿõ â øàáëîíàõ
gulp.watch(basedir+'/**/*.ftl', function(file){ plugins.livereload.changed("file") });
gulp.watch( path.src.css + '/*.css', ['compile:css'] );
gulp.watch( path.out.js + '/**/*.js', ['compile:js'] );
});