-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
95 lines (84 loc) · 2.32 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
/* eslint-disable no-undef */
'use strict';
const gulp = require(`gulp`);
const sass = require(`gulp-sass`);
const plumber = require(`gulp-plumber`);
const postcss = require(`gulp-postcss`);
const sourcemap = require(`gulp-sourcemaps`);
const posthtml = require(`gulp-posthtml`);
const autoprefixer = require(`autoprefixer`);
const htmlmin = require(`gulp-htmlmin`);
const minify = require(`gulp-csso`);
const rename = require(`gulp-rename`);
const imagemin = require(`gulp-imagemin`);
const include = require(`posthtml-include`);
const del = require(`del`);
const uglify = require(`gulp-uglify`);
const server = require(`browser-sync`).create();
gulp.task(`style`, () =>
gulp.src(`source/sass/style.scss`)
.pipe(plumber())
.pipe(sourcemap.init())
.pipe(sass())
.pipe(postcss([
autoprefixer()
]))
.pipe(minify())
.pipe(rename(`style.min.css`))
.pipe(gulp.dest(`docs/css`))
.pipe(rename(`style.css`))
.pipe(sourcemap.write(`.`))
.pipe(gulp.dest(`docs/css`))
.pipe(server.stream())
);
gulp.task(`gulp-uglify`, () =>
gulp.src(`source/js/script.js`)
.pipe(uglify())
.pipe(rename(`script.min.js`))
.pipe(gulp.dest(`docs/js`))
);
gulp.task(`images`, () =>
gulp.src([`source/img/**/*.{png,jpg,svg}`, `!source/img/sprite.svg`])
.pipe(imagemin([
imagemin.optipng({optimizationLevel: 3}),
imagemin.jpegtran({progressive: true}),
imagemin.svgo()
]))
.pipe(gulp.dest(`docs/img`))
);
gulp.task(`html`, () =>
gulp.src(`source/*html`)
.pipe(posthtml([
include()
]))
.pipe(gulp.dest(`docs`))
);
gulp.task(`minify`, () =>
gulp.src(`source/*.html`)
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest(`docs`))
);
gulp.task(`serve`, () => {
server.init({
server: `docs/`,
notify: false,
open: false,
cors: true,
ui: false
});
gulp.watch(`source/sass/**/*.{scss,sass}`, gulp.series(`style`));
gulp.watch(`source/*.html`, gulp.series(`html`));
gulp.watch(`source/*.html`).on(`change`, server.reload);
});
gulp.task(`copy`, () =>
gulp.src([
`source/fonts/**/*.{woff,woff2}`,
`source/img/**`,
`source/js/**`
], {
base: `source`
})
.pipe(gulp.dest(`docs`))
);
gulp.task(`clean`, () => del(`docs`));
gulp.task(`build`, gulp.series(`clean`, `copy`, `style`, `gulp-uglify`, `images`, `html`));