-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
157 lines (136 loc) · 3.58 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
/**
* Gulpfile
* ---
* Installation
* yarn add gulp gulp-sass gulp-postcss gulp-sourcemaps autoprefixer cssnano postcss-reporter css-mqpacker del gulp-plumber gulp-connect postcss-assets gulp-imagemin gulp-svgstore gulp-cheerio gulp-plumber inuitcss
* During development run:
* gulp
*
* Build your project before commit:
* gulp build
*/
var gulp = require('gulp');
var sass = require('gulp-sass');
var postcss = require('gulp-postcss');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('autoprefixer');
var cssnano = require('cssnano');
var sorting = require('postcss-sorting');
var reporter = require('postcss-reporter');
var mqpacker = require('css-mqpacker');
var del = require('del');
var plumber = require('gulp-plumber');
var connect = require('gulp-connect')
var assets = require('postcss-assets');
var imagemin = require('gulp-imagemin');
var svgstore = require('gulp-svgstore');
var cheerio = require('gulp-cheerio');
/**
* Styles
*/
gulp.task('styles', function() {
/**
* Setup PostCSS Proprocessors
*/
var processors = [
autoprefixer({ browsers: ['last 2 versions'] }),
mqpacker,
assets(
{
basePath: 'templates/src/',
loadPaths: ['img/'],
relative: true,
cachebuster: true
}),
cssnano({
core: false,
discardComments: {
removeAll: true
},
colormin: false
}),
sorting({})
];
return gulp.src('templates/src/scss/**/*.scss')
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(sass({outputStyle: 'expanded'}))
.pipe(postcss(processors))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('templates/css'))
.pipe(connect.reload());
});
/**
* Scripts
*/
gulp.task('scripts', function() {
return gulp.src(['templates/src/js/**/*.js'])
.pipe(gulp.dest('templates/js'))
.pipe(connect.reload());
});
/**
* Images
*/
gulp.task('images', function() {
return gulp.src('templates/src/img/*')
.pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
.pipe(gulp.dest('templates/img'))
});
/**
* SVG icons
*/
gulp.task('icons', function () {
return gulp.src('templates/src/icons/*')
.pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
.pipe(svgstore({ fileName: 'icons.svg', inlineSvg: true}))
.pipe(cheerio({
run: function ($, file) {
$('svg').addClass('hide');
$('[fill]').removeAttr('fill');
$('[stroke]').removeAttr('stroke');
},
parserOptions: { xmlMode: true }
}))
.pipe(gulp.dest('templates/img'))
});
/**
* HTML templates
*/
gulp.task('html', function () {
gulp.src('templates/src/html/**/*.html')
.pipe(connect.reload());
});
/**
* Connect
*/
gulp.task('connect', function() {
connect.server({
root: 'templates',
livereload: true
});
});
/**
* Clean
*/
gulp.task('clean', function() {
return del(['templates/css/**', 'templates/js/**', 'templates/img/**']);
});
/**
* Watch Task
*/
gulp.task('watch', function() {
// Watch .scss files
gulp.watch('templates/src/scss/**/*.scss', ['styles']);
// Watch .js files
gulp.watch('templates/src/js/**/*.js', ['scripts']);
// Watch image files
gulp.watch('templates/src/img/**/*', ['images']);
// Watch icon files
gulp.watch('templates/src/icons/*', ['icons']);
// Watch html files
gulp.watch('templates/src/html/**/*.html', ['html']);
});
/**
* Default
*/
gulp.task('default', ['connect', 'styles', 'scripts', 'images', 'icons', 'watch']);