-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
126 lines (115 loc) · 3.82 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const gulp = require("gulp");
const imagemin = require("gulp-imagemin");
const cssmin = require("gulp-cssmin");
const rename = require("gulp-rename");
const scss = require("gulp-sass")(require("sass"));
const minify = require("gulp-minify");
const autoprefixer = require("gulp-autoprefixer");
const concat = require("gulp-concat");
// const htmlmin = require("gulp-htmlmin"); // Nuevo módulo añadido
/**
* Object that defines the paths for different assets in the project.
* @type {Object}
* @property {Object} styles_scss - Paths for SCSS stylesheets.
* @property {string[]} styles_scss.src - Source paths for SCSS files.
* @property {string} styles_scss.dest - Destination path for compiled CSS files.
* @property {Object} styles_css - Paths for CSS stylesheets.
* @property {string} styles_css.src - Source path for CSS files.
* @property {string} styles_css.dest - Destination path for CSS files.
* @property {Object} scripts - Paths for JavaScript files.
* @property {string} scripts.src - Source path for JavaScript files.
* @property {string} scripts.dest - Destination path for JavaScript files.
* @property {Object} images - Paths for image files.
* @property {string} images.src - Source path for image files.
* @property {string} images.dest - Destination path for image files.
* @property {Object} fonts - Paths for font files.
* @property {string} fonts.src - Source path for font files.
* @property {string} fonts.dest - Destination path for font files.
* @property {Object} html - Paths for HTML files.
* @property {string} html.src - Source path for HTML files.
* @property {string} html.dest - Destination path for HTML files.
*/
const paths = {
styles_scss: {
src: ["static/src/scss/**/*.scss", "!static/src/scss/vars.scss"],
dest: "static/src/css",
},
styles_css: {
src: "static/src/css/*.css",
dest: "static/dist/css",
},
scripts: {
src: "static/src/js/**/*.js",
dest: "static/dist/js",
},
images: {
src: "static/src/images/**/*",
dest: "static/dist/images",
},
fonts: {
src: "static/src/fonts/**/*",
dest: "static/dist/fonts",
},
html: {
src: "static/src/*.html", // Actualiza la ruta según tu estructura de archivos HTML
dest: "static/dist",
},
};
function compileSass() {
return gulp
.src(paths.styles_scss.src)
.pipe(scss({ bundleExec: true }))
.pipe(autoprefixer({ overrideBrowserslist: ["> .5%, last 2 versions"] }))
.pipe(gulp.dest(paths.styles_scss.dest));
}
function minifyCSS() {
return gulp
.src(paths.styles_css.src)
.pipe(cssmin())
.pipe(rename({ suffix: ".min" }))
.pipe(gulp.dest(paths.styles_css.dest));
}
function minifyScripts() {
return gulp
.src(paths.scripts.src)
.pipe(minify())
.pipe(gulp.dest(paths.scripts.dest));
}
function optimizeImages() {
return gulp
.src(paths.images.src)
.pipe(imagemin([imagemin.mozjpeg({ quality: 100, progressive: true })]))
.pipe(gulp.dest(paths.images.dest));
}
function optimizeFonts() {
return gulp
.src(paths.fonts.src)
.pipe(imagemin())
.pipe(gulp.dest(paths.fonts.dest));
}
const jsFiles = ["static/src/js/partials/Header.js"];
function combineScripts() {
return gulp
.src([...jsFiles]) // Combina jsFiles y contactJsFiles
.pipe(concat("Home.js"))
.pipe(gulp.dest("static/src/js"));
}
function watchFiles() {
gulp.watch(paths.images.src, optimizeImages);
gulp.watch(paths.styles_scss.src, compileSass);
gulp.watch(paths.styles_css.src, minifyCSS);
gulp.watch(jsFiles, combineScripts);
gulp.watch(paths.scripts.src, minifyScripts);
gulp.watch(paths.fonts.src, optimizeFonts);
}
const buildTasks = gulp.parallel(
compileSass,
minifyCSS,
minifyScripts,
optimizeImages,
combineScripts,
optimizeFonts
);
exports.build = buildTasks;
exports.watch = gulp.series(buildTasks, watchFiles);
exports.default = buildTasks;