-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
144 lines (104 loc) · 3.21 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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 cssminifiy = require('gulp-clean-css');
var gulp = require('gulp');
var gutil = require('gulp-util');
var notify = require('gulp-notify');
var plumber = require('gulp-plumber');
var reload = browserSync.reload;
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
// > Gestiona los errores
var onError = function (err) {
gutil.beep();
console.log(err);
};
// > Procesa los archivos SASS/SCSS, añade sourcemaps y autoprefixer
gulp.task('styles', function(cb) {
return 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}));
});
// > Procesa los archivos SASS/SCSS, sin sourcemaps, minimizados y con autoprefixer
gulp.task('styles-min', function(cb) {
return 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}));
});
// > Procesa los scripts concatenando
gulp.task('scripts', function(){
return 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}));
});
// > Procesa los scripts concatenando, minimizando y sin sourcemaps
gulp.task('scripts-min', function(){
return 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}));
});
// > Arranca el servidor web con BrowserSync
gulp.task('default', ['styles', 'scripts'], function () {
browserSync.init({
server : {
baseDir: "./"
},
ghostMode: false,
online: true
});
gulp.watch(config.images, ['bs-reload']);
gulp.watch(config.scss.src, ['styles']);
gulp.watch(config.js.src, ['bs-reload', ['scripts']]);
gulp.watch(config.html, ['bs-reload']);
});
// > Genera una versión lista para producción
gulp.task('deploy', ['styles-min', 'scripts-min'], function () {
});
// > Recarga las ventanas del navegador
gulp.task('bs-reload', function () {
browserSync.reload();
});