-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
112 lines (99 loc) · 3.5 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
const gulp = require('gulp');
const browserSync = require('browser-sync');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify-es').default;
const sass = require('gulp-sass')(require('sass'));
const cleanCSS = require('gulp-clean-css');
const autoprefixer = require('gulp-autoprefixer');
const rename = require("gulp-rename");
const imagemin = require('gulp-imagemin');
const ttf2woff = require('gulp-ttf2woff');
const ttf2woff2 = require('gulp-ttf2woff2');
const webp = require('gulp-webp');
// const avif = require('gulp-avif');
// Check if the build is for deployment (Vercel) or development
// const isProduction = process.env.VERCEL === '1';
// Check if the build is for deployment (Netlify) or development
const isProduction = process.env.NETLIFY === 'true';
const server = function() {
if (!isProduction) {
browserSync({
server: {
baseDir: "dist"
}
});
}
gulp.watch("src/*.html").on('change', browserSync.reload);
};
const styles = function() {
return gulp.src("src/sass/**/*.+(scss|sass)")
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(rename({suffix: '.min', prefix: ''}))
.pipe(autoprefixer())
.pipe(cleanCSS())
.pipe(gulp.dest("dist/css"))
.pipe(browserSync.stream());
};
const html = function () {
return gulp.src("src/*.html")
.pipe(gulp.dest("dist/"));
};
const scripts = function () {
return gulp.src([
'node_modules/swiper/swiper-bundle.min.js',
'src/js/**/*.js'
])
.pipe(concat('main.min.js'))
.pipe(uglify())
.pipe(gulp.dest("dist/js"))
.pipe(browserSync.stream());
};
const fonts = function () {
return gulp.src('src/fonts/*.ttf')
.pipe(ttf2woff())
.pipe(gulp.dest('dist/fonts'))
.pipe(gulp.src('src/fonts/*.ttf'))
.pipe(ttf2woff2())
.pipe(gulp.dest('dist/fonts'));
};
const icons = function () {
return gulp.src("src/icons/**/*")
.pipe(gulp.dest("dist/icons"))
.pipe(browserSync.stream());
};
const images = function () {
return gulp.src("src/img/**/*")
.pipe(imagemin())
.pipe(gulp.dest("dist/img"))
.pipe(browserSync.stream());
};
const webpImages = function() {
return gulp.src("src/img/**/*.{png,jpg,jpeg}")
.pipe(webp())
.pipe(gulp.dest("dist/img"));
};
const watch = function() {
gulp.watch("src/sass/**/*.+(scss|sass|css)", gulp.parallel(styles));
gulp.watch("src/*.html").on('change', gulp.parallel(html));
gulp.watch("src/js/**/*.js").on('change', gulp.parallel(scripts));
gulp.watch("src/fonts/*").on('all', gulp.parallel(fonts));
gulp.watch("src/icons/**/*").on('all', gulp.parallel(icons));
gulp.watch("src/img/**/*").on('all', gulp.parallel(images));
gulp.watch("src/img/**/*.{png,jpg,jpeg}", gulp.parallel(webpImages));
};
exports.server = server;
exports.styles = styles;
exports.html = html;
exports.scripts = scripts;
exports.fonts = fonts;
exports.icons = icons;
exports.images = images;
exports.webpImages = webpImages;
exports.watch = watch;
// exports.default = gulp.parallel(watch, server, images, webpImages, styles, scripts, fonts, icons, html);
// Update exports.default to only include necessary tasks for build
if (isProduction) {
exports.default = gulp.series(images, webpImages, styles, scripts, fonts, icons, html);
} else {
exports.default = gulp.parallel(watch, server, images, webpImages, styles, scripts, fonts, icons, html);
}