-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
63 lines (55 loc) · 1.73 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
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/**/*'
}
function css() {
return src(paths.scss)
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(postcss([autoprefixer(), cssnano()]))
// .pipe(postcss([autoprefixer()]))
.pipe(sourcemaps.write('.'))
.pipe(dest('build/css'));
}
function javascript() {
return src(paths.js)
.pipe(sourcemaps.init())
.pipe(concat('bundle.js'))
.pipe(terser())
.pipe(sourcemaps.write('.'))
.pipe(rename({ suffix: '.min' }))
.pipe(dest('./build/js'));
}
function imagenes() {
return src(paths.imagenes)
.pipe(cache(imagemin({ optimizationLevel: 3 })))
.pipe(dest('build/img'));
}
function versionWebp() {
return src(paths.imagenes)
.pipe(webp())
.pipe(dest('build/img'));
}
function watchArchivos() {
watch(paths.scss, css);
watch(paths.js, javascript);
watch(paths.imagenes, imagenes);
watch(paths.imagenes, versionWebp);
}
exports.css = css;
exports.watchArchivos = watchArchivos;
exports.dev = parallel(css, javascript, imagenes, versionWebp, watchArchivos);