-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
142 lines (133 loc) · 2.73 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
const { src, dest, parallel, watch } = require('gulp');
const sass = require('gulp-sass')(require('sass'));
const uglify = require('gulp-uglify');
const sourcemaps = require('gulp-sourcemaps');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const rename = require('gulp-rename');
const pug = require('gulp-pug');
const imagemin = require('gulp-imagemin');
const browserSync = require('browser-sync').create();
const del = require('del');
async function clean(done) {
del(['dist']);
done();
}
function styles() {
return src('src/scss/*.scss')
.pipe(sourcemaps.init())
.pipe(
sass({
errLogToConsole: true,
outputStyle: 'expanded',
})
)
.on('error', console.error.bind(console))
.pipe(
postcss([
autoprefixer({
cascade: false,
grid: true,
}),
])
)
.pipe(dest('dist/css'))
.pipe(
rename({
suffix: '.min',
})
)
.pipe(
sass({
errLogToConsole: true,
outputStyle: 'compressed',
})
)
.pipe(
sourcemaps.write('/', {
includeContent: false,
sourceRoot: '../../src/sass',
})
)
.pipe(dest('dist/css'))
.pipe(browserSync.stream());
}
function pug_html() {
return src('src/pug/*.pug')
.pipe(
pug({
pretty: true,
})
)
.pipe(dest('dist'))
.pipe(browserSync.stream());
}
function html() {
return src('src/*.html').pipe(dest('dist')).pipe(browserSync.stream());
}
function scripts() {
return src('src/js/**/*.js')
.pipe(dest('dist/js'))
.pipe(uglify())
.pipe(
rename({
suffix: '.min',
})
)
.pipe(dest('dist/js'))
.pipe(browserSync.stream());
}
function images() {
return src('src/img/**/*')
.pipe(
imagemin([
imagemin.gifsicle({ interlaced: true }),
imagemin.mozjpeg({ quality: 85, progressive: true }),
imagemin.optipng({ optimizationLevel: 5 }),
imagemin.svgo({
plugins: [{ removeViewBox: true }, { cleanupIDs: false }],
}),
])
)
.pipe(dest('dist/img'))
.pipe(browserSync.stream());
}
function sync(done) {
browserSync.init({
server: {
baseDir: './dist',
},
});
done();
}
function watcher() {
watch('src/scss/**/*.scss', { events: 'all', delay: 100 }, styles);
watch('src/pug/**/*.pug', { events: 'all', delay: 100 }, pug_html);
watch('src/**/*.html', { events: 'all', delay: 100 }, html);
watch('src/js/**/*.js', { events: 'all', delay: 100 }, scripts);
watch(
[
'src/img/**/*.png',
'src/img/**/*.jpg',
'src/img/**/*.svg',
'src/img/**/*.gif',
],
{ events: 'all', delay: 100 },
images
);
}
exports.styles = styles;
exports.pug_html = pug_html;
exports.scripts = scripts;
exports.images = images;
exports.sync = sync;
exports.clean = clean;
exports.default = parallel(
styles,
html,
scripts,
pug_html,
images,
sync,
watcher
);