-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
87 lines (71 loc) · 2.15 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
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 SASS */
.pipe(sourcemaps.init())
.pipe(plumber()) //** Evitar errores de SASS */
.pipe( sass()) //** Compilarlo */
.pipe( postcss( [autoprefixer(), cssnano()]) ) //** Agregar prefijos */
.pipe(sourcemaps.write('.'))
.pipe(dest('build/css')); //** Almacenarlo en el disco duro */
done(); //** Callback que avisa a gulp cuando llegamos al final */
}
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( css, imagenes, versionWebp,versionAvif, javaScript, dev);