-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
127 lines (105 loc) · 3.3 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
127
'use strict';
var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync');
var combineMq = require('gulp-combine-mq');
var concat = require('gulp-concat');
var config = require('./config.json');
var gulp = require('gulp');
var notify = require('gulp-notify');
var plumber = require('gulp-plumber');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
// > Procesa los archivos SASS/SCSS, añade sourcemaps y autoprefixer
gulp.task('styles', function(done) {
gulp.src(config.scss.src)
.pipe(sourcemaps.init())
.pipe(plumber({errorHandler: notify.onError('Error: <%= error.message %>')}))
.pipe(sass({
outputStyle: 'extended',
}))
.pipe(combineMq({
beautify: true
}))
.pipe(autoprefixer({
browsers: [
'last 2 versions',
'ie >= 10'
],
cascade: false
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(config.scss.dest))
.pipe(browserSync.reload({ stream:true }));
//.pipe(notify({message: 'CSS OK', onLast: true}));
done();
});
// > Procesa los archivos SASS/SCSS, sin sourcemaps, minimizados y con autoprefixer
gulp.task('styles-min', function(done) {
gulp.src(config.scss.src)
.pipe(plumber({errorHandler: notify.onError('Error: <%= error.message %>')}))
.pipe(sass({
outputStyle: 'compressed',
}))
.pipe(combineMq({
beautify: false
}))
.pipe(autoprefixer({
browsers: [
'last 2 versions',
'ie >= 10'
],
cascade: false
}))
.pipe(gulp.dest(config.scss.dest))
.pipe(notify({message: 'CSS MIN OK', onLast: true}));
done();
});
// > Procesa los scripts concatenando
gulp.task('scripts', function(done){
gulp.src(config.js.src)
.pipe(sourcemaps.init())
.pipe(plumber({errorHandler: notify.onError('Error: <%= error.message %>')}))
.pipe(concat('main.min.js'))
//.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(config.js.dest))
.pipe(browserSync.reload({ stream:true }));
//.pipe(notify({message: 'JS OK', onLast: true}));
done();
});
// > Procesa los scripts concatenando, minimizando y sin sourcemaps
gulp.task('scripts-min', function(done){
gulp.src(config.js.src)
.pipe(plumber({errorHandler: notify.onError('Error: <%= error.message %>')}))
.pipe(concat('main.min.js'))
.pipe(uglify())
.pipe(gulp.dest(config.js.dest))
.pipe(notify({message: 'JS MIN OK', onLast: true}));
done();
});
// > Arranca el servidor web con BrowserSync
gulp.task('default', gulp.series(['styles','scripts'], function(done) {
browserSync.init({
server : {
baseDir: './'
},
ghostMode: false,
online: true
});
gulp.watch(config.images, gulp.series('bs-reload'));
gulp.watch(config.scss.src, gulp.series('styles'));
gulp.watch(config.js.src, gulp.series(['scripts', 'bs-reload']));
gulp.watch(config.html, gulp.series('bs-reload'));
done();
}));
// > Genera una versión lista para producción
gulp.task('deploy', gulp.series(['styles-min','scripts-min'], function(done) {
console.log('> Versión de producción: OK');
done();
}));
// > Recarga las ventanas del navegador
gulp.task('bs-reload', function (done) {
browserSync.reload();
done();
});