-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
65 lines (56 loc) · 1.86 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
const { src, dest, watch , 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');
const notify = require('gulp-notify');
const cache = require('gulp-cache');
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('./build/css') );
}
function javascript() {
return src(paths.js)
.pipe(sourcemaps.init())
.pipe(concat('bundle.js')) // final output file name
.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'))
.pipe(notify({ message: 'Imagen Completada'}));
}
function versionWebp() {
return src(paths.imagenes)
.pipe( webp() )
.pipe(dest('build/img'))
.pipe(notify({ message: 'Imagen Completada'}));
}
function watchArchivos() {
watch( paths.scss, css );
watch( paths.js, javascript );
watch( paths.imagenes, imagenes );
watch( paths.imagenes, versionWebp );
}
exports.default = parallel(css, javascript, imagenes, versionWebp, watchArchivos );