-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
82 lines (71 loc) · 1.98 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
const { src, dest, watch, parallel } = require('gulp');
// CSS
const sass = require('gulp-sass')(require('sass'));
const plumber = require('gulp-plumber');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const postcss = require('gulp-postcss');
const sourcemaps = require('gulp-sourcemaps');
// Imagenes
const cache = require('gulp-cache');
const imagemin = require('gulp-imagemin');
const webp = require('gulp-webp');
const avif = require('gulp-avif');
// JavaScript
const terser = require('gulp-terser-js');
function css(done) {
src('src/scss/**/*.scss') // Identificar el archivo.scss a compilar
.pipe(sourcemaps.init())
.pipe(plumber())
.pipe( sass()) //Compilarlo
.pipe(postcss([autoprefixer(), cssnano()]))
.pipe(sourcemaps.write('.'))
.pipe( dest('build/css')) // Almacenarla en el disco duro
done();
}
function imagenes(done) {
const opciones = {
optimizationLevel: 3
}
src('src/img/**/*.{png,jpg}')
.pipe(cache(imagemin(opciones)))
.pipe(dest('build/img'))
done();
}
function versionWebp (done) {
const opciones = {
quality: 50
};
src('src/img/**/*.{png,jpg}')
.pipe(webp(opciones))
.pipe(dest('build/img'))
done();
}
function versionAvif (done) {
const opciones = {
quality: 50
};
src('src/img/**/*.{png,jpg}')
.pipe(avif(opciones))
.pipe(dest('build/img'))
done();
}
function javascript(done) {
src('src/js/**/*.js')
.pipe(sourcemaps.init())
.pipe(terser())
.pipe(sourcemaps.write('.'))
.pipe(dest('build/js'))
done();
}
function dev(done) {
watch('src/scss/**/*.scss', css)
watch('src/js/**/*.js', javascript)
done();
}
exports.css = css;
exports.js = javascript;
exports.imagenes = imagenes;
exports.versionWebp = versionWebp;
exports.versionAvif = versionAvif;
exports.dev = parallel(imagenes, versionWebp, versionAvif, javascript, dev);