generated from RomanVinichenko/template-gulp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
88 lines (78 loc) · 2.29 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
const { src, dest, watch, parallel, series } = require('gulp');
const browserSync = require('browser-sync').create();
const scss = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify');
const htmlmin = require('gulp-html-minifier-terser');
const concat = require('gulp-concat');
const del = require('del');
const browsersync = () => {
browserSync.init({
server: {
baseDir: 'app/',
},
notify: false,
});
};
const watching = () => {
watch(['app/*.html']).on('change', browserSync.reload);
watch(['app/scss/**/*.scss'], styles);
watch(['app/js/index.js', '!app/js/index.min.js', '!app/js/index.min.js.map'], scripts);
};
const styles = () => {
return src('app/scss/style.scss')
.pipe(sourcemaps.init())
.pipe(scss({ outputStyle: 'compressed' }))
.pipe(concat('style.min.css'))
.pipe(
autoprefixer({
overrideBrowserslist: ['last 10 version'],
grid: true,
}),
)
.pipe(sourcemaps.write('.'))
.pipe(dest('app/css'))
.pipe(browserSync.stream());
};
const scripts = () => {
return src(['app/js/index.js'])
.pipe(sourcemaps.init())
.pipe(concat('index.min.js'))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(dest('app/js'))
.pipe(browserSync.stream());
};
const cleanDist = () => {
return del('dist');
};
const htmls = () => {
return src('app/*.html')
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(dest('dist/'));
};
const build = () => {
return src(
[
'app/css/style.min.css',
'app/css/style.min.css.map',
'app/js/index.min.js',
'app/js/index.min.js.map',
'app/fonts/**/*',
'app/images/**/*',
],
{
base: 'app',
},
).pipe(dest('dist'));
};
exports.styles = styles;
exports.scripts = scripts;
exports.browsersync = browsersync;
exports.watching = watching;
exports.build = build;
exports.cleanDist = cleanDist;
exports.htmls = htmls;
exports.build = series(cleanDist, htmls, build);
exports.default = parallel(styles, scripts, browsersync, watching);