-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgulpfile.babel.js
158 lines (136 loc) · 3.23 KB
/
gulpfile.babel.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//HTML
import htmlmin from 'gulp-htmlmin';
//CSS
import postcss from 'gulp-postcss';
import cssnano from 'cssnano';
import autoprefixer from 'autoprefixer';
//JavaScript
import gulp from 'gulp';
import babel from 'gulp-babel';
import terser from 'gulp-terser';
//PUG
import pug from 'gulp-pug';
//SASS
import sass from 'gulp-sass';
//Common
import concat from 'gulp-concat';
//Clean CSS
import clean from 'gulp-purgecss';
//Caché bust
import cacheBust from 'gulp-cache-bust';
//Optimización imágenes
import imagemin from 'gulp-imagemin';
//Browser sync
import { init as server, stream, reload } from 'browser-sync';
//Plumber
import plumber from 'gulp-plumber';
//Typescript
import ts from 'gulp-typescript';
const production = false;
//Variables/constantes
const cssPlugins = [cssnano(), autoprefixer()];
gulp.task('html-min', () => {
return gulp
.src('./src/*.html')
.pipe(plumber())
.pipe(
htmlmin({
collapseWhitespace: true,
removeComments: true
})
)
.pipe(gulp.dest('./public'));
});
gulp.task('styles', () => {
return gulp
.src('./src/css/*.css')
.pipe(plumber())
.pipe(concat('styles-min.css'))
.pipe(postcss(cssPlugins))
.pipe(gulp.dest('./public/css'))
.pipe(stream());
});
gulp.task('babel', () => {
return gulp
.src('./src/js/*.js')
.pipe(plumber())
.pipe(concat('scripts-min.js'))
.pipe(babel())
.pipe(terser())
.pipe(gulp.dest('./public/js'));
});
gulp.task('views', () => {
return gulp
.src('./src/views/pages/*.pug')
.pipe(plumber())
.pipe(
pug({
pretty: production ? false : true
})
)
.pipe(
cacheBust({
type: 'timestamp'
})
)
.pipe(gulp.dest('./public'));
});
gulp.task('sass', () => {
return gulp
.src('./src/scss/styles.scss')
.pipe(plumber())
.pipe(
sass({
outputStyle: 'compressed'
})
)
.pipe(postcss(cssPlugins))
.pipe(gulp.dest('./public/css'))
.pipe(stream());
});
gulp.task('clean', () => {
return gulp
.src('./public/css/styles.css')
.pipe(plumber())
.pipe(
clean({
content: ['./public/*.html']
})
)
.pipe(gulp.dest('./public/css'));
});
gulp.task('imgmin', () => {
return gulp
.src('./src/images/*')
.pipe(plumber())
.pipe(
imagemin([
imagemin.gifsicle({ interlaced: true }),
imagemin.mozjpeg({ quality: 30, progressive: true }),
imagemin.optipng({ optimizationLevel: 1 })
])
)
.pipe(gulp.dest('./public/images'));
});
gulp.task('typescript', () => {
return gulp
.src('src/ts/*.ts')
.pipe(
ts({
noImplicitAny: true,
outFile: 'using-ts.js'
})
)
.pipe(gulp.dest('public/js'));
});
gulp.task('default', () => {
server({
server: './public'
});
// gulp.watch('./src/*.html', gulp.series('html-min')).on('change', reload)
// gulp.watch('./src/css/*.css', gulp.series('styles'))
gulp.watch('./src/views/**/*.pug', gulp.series('views')).on('change', reload);
gulp.watch('./src/scss/**/*.scss', gulp.series('sass'));
// gulp.watch('./src/js/*.js', gulp.series('babel')).on('change', reload);
gulp.watch('./src/ts/*.ts', gulp.series('typescript')).on('change', reload);
});