-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
75 lines (57 loc) · 2.08 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
const { src, dest, watch, series } = require('gulp'); // npm install --save-dev gulp@4.0.2
const sass = require('gulp-sass')(require('sass')); // npm install --save-dev sass gulp-sass
const postcss = require('gulp-postcss'); // npm install --save-dev gulp-postcss postcss
const autoprefixer = require('autoprefixer'); // npm install --save-dev autoprefixer
const imagemin = require('gulp-imagemin'); // npm install --save-dev gulp-imagemin@7.1.0
const webp = require('gulp-webp'); // npm install --save-dev gulp-webp@4.0.1
const avif = require('gulp-avif'); // npm install --save-dev gulp-avif
const sourcemaps = require('gulp-sourcemaps'); // npm install --save-dev gulp-sourcemaps
const cssnano = require('cssnano'); // npm install --save-dev cssnano
// Compile SASS files to CSS
const css = (done) => {
src('./src/scss/**/*.scss') // Source files
.pipe(sourcemaps.init()) // Initialize sourcemaps
.pipe(sass({ outputStyle: 'expanded' })) // Compile SASS to CSS
.pipe(postcss([autoprefixer(), cssnano()])) // Add vendor prefixes
.pipe(sourcemaps.write('.')) // Write sourcemaps
.pipe(dest('./build/css')); // Output folder
done();
};
// Copy images to build folder
const imagenes = (done) => {
src('./src/img/**/*')
.pipe(imagemin({ optimizationLevel: 3 }))
.pipe(dest('./build/img'));
done();
}
// Convert images to WebP format
const versionWebp = (done) => {
const opciones = {
quality: 50
}
src('./src/img/**/*.{jpg,jpeg,png}')
.pipe(webp(opciones))
.pipe(dest('./build/img'));
done();
}
// Convert images to AVIF format
const versionAvif = (done) => {
const opciones = {
quality: 50
}
src('./src/img/**/*.{jpg,jpeg,png}')
.pipe(avif(opciones))
.pipe(dest('./build/img'));
done();
}
// Watch for changes in SASS files
const dev = () => {
watch('./src/scss/**/*.scss', css);
watch('./src/img/**/*', imagenes);
};
exports.css = css;
exports.dev = dev;
exports.imagenes = imagenes;
exports.versionWebp = versionWebp;
exports.versionAvif = versionAvif;
exports.default = series(imagenes, versionWebp, versionAvif, css, dev);