-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
136 lines (116 loc) · 3.16 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
const gulp = require('gulp');
const concat = require('gulp-concat');
const autopref = require('gulp-autoprefixer');
const cleanCSS = require('gulp-clean-css');
const uglify = require('gulp-uglify');
const del = require('del');
const browserSync = require('browser-sync').create();
const imagemin = require('gulp-imagemin');
const sourcemaps = require('gulp-sourcemaps');
const babel = require("gulp-babel");
const rename = require("gulp-rename");
const sass = require("gulp-sass");
const ttf2woff = require('gulp-ttf2woff');
const ttf2woff2 = require('gulp-ttf2woff2');
const src = {
js: './src/js/**/*',
css: './src/sass/**/*',
img: './src/img/**/*',
lib: './src/lib/**/*',
fonts: './src/fonts/**/*',
}
// WATCH
function presass() {
return gulp.src('./src/sass/main.sass')
.pipe(
sass({
outputStyle: "expanded"
})
)
.pipe(autopref())
.pipe(sourcemaps.init())
.pipe(concat(`style.css`))
.pipe(gulp.dest('./build/css/'))
.pipe(cleanCSS({
level: 2
}))
.pipe(
rename({
extname: ".min.css"
})
)
.pipe(sourcemaps.write('/srcmaps/'))
.pipe(gulp.dest('./build/css/'))
.pipe(browserSync.stream())
}
function scripts() {
return gulp.src(src.js)
.pipe(babel())
.on('error', console.error.bind(console))
.pipe(concat(`script.js`))
.pipe(gulp.dest('./build/js/'))
.pipe(uglify({
toplevel: true
}))
.pipe(
rename({
extname: ".min.js"
})
)
.pipe(gulp.dest(`./build/js/`))
.pipe(browserSync.stream())
}
function library(cb) {
gulp.src(src.lib)
.pipe(gulp.dest('./build/lib'))
cb()
}
function fonts(cb) {
gulp.src(['./src/fonts/*.ttf'])
.pipe(ttf2woff())
.pipe(gulp.dest('./build/fonts/'));
return gulp.src(['./src/fonts/*.ttf'])
.pipe(ttf2woff2())
.pipe(gulp.dest('./build/fonts/'));
return gulp.src(src.fonts)
.pipe(gulp.dest('./build/fonts'))
cb()
}
function compress (cb) {
return gulp.src(src.img)
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
interlaced: true,
optimizationlevel: 3
}))
.pipe(gulp.dest(`./build/img/`))
.pipe(browserSync.stream())
cb()
}
function clean() {
return del(['build/css/*','build/fonts/*','build/img/*','build/js/*'])
}
function watch() {
browserSync.init({
server: {
baseDir: "./"
}
});
// SASS
gulp.watch(src.css, presass)
gulp.watch(src.img, compress)
gulp.watch(src.js, scripts)
gulp.watch(src.lib, library)
gulp.watch(src.fonts, fonts)
gulp.watch("./*.html").on('change', browserSync.reload);
}
//gulp.task('watch', watch);
gulp.task('build', gulp.series(clean, gulp.parallel(fonts, presass, scripts, compress, library)));
gulp.task('watch', gulp.series(clean, gulp.parallel(fonts, presass, scripts, compress, library), watch));
gulp.task('dev', gulp.series('build', 'watch'));
gulp.task('clean', clean);
gulp.task('compress', compress);
gulp.task('devsass', presass);
gulp.task('devscripts', scripts);
gulp.task('fonts', fonts);