-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
85 lines (77 loc) · 2.12 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
const { src, dest, watch, series, parallel } = require("gulp");
const sass = require("gulp-sass")(require("sass"));
const autoprefixer = require("autoprefixer");
const postcss = require("gulp-postcss");
const sourcemaps = require("gulp-sourcemaps");
const cssnano = require("cssnano");
const concat = require("gulp-concat");
const terser = require("gulp-terser-js");
const rename = require("gulp-rename");
const imagemin = require("gulp-imagemin"); // Minificar imagenes
const cache = require("gulp-cache");
const clean = require("gulp-clean");
const webp = require("gulp-webp");
const paths = {
scss: "src/scss/**/*.scss",
js: "src/js/**/*.js",
imagenes: "src/img/**/*",
};
// css es una función que se puede llamar automaticamente
function css() {
return (
src(paths.scss)
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(postcss([autoprefixer(), cssnano()]))
// .pipe(postcss([autoprefixer()]))
.pipe(sourcemaps.write("."))
.pipe(dest("public/build/css"))
);
}
function javascript() {
return src(paths.js)
.pipe(terser())
.pipe(sourcemaps.write("."))
.pipe(dest("public/build/js"));
}
function imagenes() {
return src(paths.imagenes)
.pipe(
cache(
imagemin({
optimizationLevel: 3,
})
)
)
.pipe(dest("public/build/img"));
}
function versionWebp() {
return src(paths.imagenes).pipe(webp()).pipe(dest("public/build/img"));
}
function watchArchivos() {
watch(paths.scss, css);
watch(paths.js, javascript);
watch(paths.imagenes, imagenes);
watch(paths.imagenes, versionWebp);
}
function cleanBuild() {
return src("./public/build", {
read: false,
allowEmpty: true,
}).pipe(
clean({
force: true,
})
);
}
exports.css = css;
exports.watchArchivos = watchArchivos;
exports.default = series(
cleanBuild,
css,
javascript,
imagenes,
versionWebp,
watchArchivos
);
exports.build = series(cleanBuild, css, javascript, imagenes, versionWebp);