-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·163 lines (146 loc) · 3.95 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
'use strict';
const { src, dest, series, parallel, watch } = require('gulp');
const sass = require('gulp-sass');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const csso = require('gulp-csso');
const gcmq = require('gulp-group-css-media-queries');
const del = require('del');
const htmlmin = require('gulp-htmlmin');
const imagemin = require('gulp-imagemin');
const svgstore = require('gulp-svgstore');
const plumber = require('gulp-plumber');
const rigger = require('gulp-rigger');
const stylelint = require('gulp-stylelint');
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');
const rename = require('gulp-rename');
const cache = require('gulp-cache');
const pug = require('gulp-pug');
const smartgrid = require('smart-grid');
const server = require('browser-sync').create();
var settings = {
outputStyle: 'scss' /* less || scss || sass || styl */,
columns: 12 /* number of grid columns */,
offset: '30px' /* gutter width px || % || rem */,
mobileFirst: false /* mobileFirst ? 'min-width' : 'max-width' */,
container: {
maxWidth: '1170px' /* max-width оn very large screen */,
fields: '0' /* side fields */,
},
breakPoints: {
lg: {
width: '1100px' /* -> @media (max-width: 1100px) */,
},
md: {
width: '960px',
},
sm: {
width: '780px',
fields:
'15px' /* set fields only if you want to change container.fields */,
},
xs: {
width: '560px',
},
},
};
smartgrid('./src/sass/helpers', settings); //edit row-offsets
function html() {
return src('src/*.html')
.pipe(rigger())
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(dest('build'));
}
function pugs() {
return src('src/pug/index.pug')
.pipe(
pug({
doctype: 'html',
pretty: false,
}),
)
.pipe(dest('build'));
}
function styles() {
return src('src/sass/styles.scss')
.pipe(plumber())
.pipe(
stylelint({
reporters: [{ formatter: 'string', console: true }],
}),
)
.pipe(sass())
.pipe(postcss([autoprefixer()]))
.pipe(gcmq())
.pipe(dest('build/css'))
.pipe(csso())
.pipe(rename('styles.min.css'))
.pipe(dest('build/css'))
.pipe(server.stream());
}
function scripts() {
return src('src/js/**/*.js')
.pipe(plumber())
.pipe(babel())
.pipe(concat('scripts.js'))
.pipe(dest('build/js'))
.pipe(uglify())
.pipe(rename('scripts.min.js'))
.pipe(dest('build/js'));
}
function sprite() {
return src('src/images/icons/**/*.svg')
.pipe(svgstore({ inlineSvg: true }))
.pipe(rename('sprite.svg'))
.pipe(dest('build/images/icons'));
}
function images() {
return src(['src/images/**/*.{png,jpg,jpeg,svg}', '!src/images/icons/**/*'])
.pipe(
cache(
imagemin([
imagemin.jpegtran({ progressive: true }),
imagemin.optipng({ optimizationLevel: 3 }),
imagemin.svgo({
plugins: [{ removeViewBox: false }, { cleanupIDs: false }],
}),
]),
),
)
.pipe(dest('build/images'));
}
function fonts() {
return src('src/fonts/**/*').pipe(dest('build/fonts'));
}
function watcher(done) {
watch('src/**/*.html').on('change', series(html, server.reload));
watch('src/**/*.pug').on('change', series(pugs, server.reload));
watch('src/sass/**/*.scss').on('change', series(styles, server.reload));
watch('src/js/**/*.js').on('change', series(scripts, server.reload));
done();
}
function serve() {
return server.init({
server: 'build',
notify: false,
open: false,
cors: true,
ui: false,
logPrefix: 'DevServer',
host: 'localhost',
port: 8080,
});
}
function clean() {
return del('./build');
}
const build = series(
clean,
parallel(sprite, images, fonts, html, pugs, styles, scripts),
);
const start = series(build, watcher, serve);
// exports.prepare = prepare;
exports.build = build;
exports.start = start;