-
Notifications
You must be signed in to change notification settings - Fork 166
/
gulpfile.babel.js
218 lines (199 loc) · 5.66 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import gulp from 'gulp'
import sass from 'gulp-sass'
import plumber from 'gulp-plumber'
import postcss from 'gulp-postcss'
import autoprefixer from 'autoprefixer'
import browserSync from 'browser-sync'
import sourcemaps from 'gulp-sourcemaps'
import browserify from 'browserify'
import babelify from 'babelify'
import buffer from 'vinyl-buffer'
import source from 'vinyl-source-stream'
import rename from 'gulp-rename'
import pug from 'gulp-pug'
import watch from 'gulp-watch'
import minify from 'gulp-minify'
import imagemin from 'gulp-imagemin'
import sitemap from 'gulp-sitemap'
import cachebust from 'gulp-cache-bust'
import tildeImporter from 'node-sass-tilde-importer'
import data from 'gulp-data'
import fs from 'fs'
const server = browserSync.create()
const postcssPlugins = [
autoprefixer({browsers: '> 1%, last 2 versions, Firefox ESR, Opera 12.1'})
]
// Compila Sass para desarrollo
gulp.task('styles-dev', () => {
gulp.src('./src/scss/styles.scss')
.pipe(sourcemaps.init())
.pipe(plumber())
.pipe(sass({
importer: tildeImporter,
sourceComments: true,
outputStyle: 'expanded'
}))
.pipe(postcss(postcssPlugins))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./docs/css/'))
.pipe(server.stream({match: '**/*.css'}))
})
// Compila Sass para producción
gulp.task('styles-build', () => {
gulp.src('./src/scss/styles.scss')
.pipe(plumber())
.pipe(sass({
importer: tildeImporter,
outputStyle: 'compressed'
}))
.pipe(postcss(postcssPlugins))
.pipe(gulp.dest('./docs/css/'))
.pipe(server.stream({match: '**/*.css'}))
})
// Compila versión CSS minificada
gulp.task('css-build-min', () => {
gulp.src('./src/scss/ed-grid-css.scss')
.pipe(plumber())
.pipe(sass({
outputStyle: 'compressed'
}))
.pipe(postcss(postcssPlugins))
.pipe(rename('ed-grid.min.css'))
.pipe(gulp.dest('./src/css/'))
})
// Compila versión CSS sin minificar
gulp.task('css-build', () => {
gulp.src('./src/scss/ed-grid-css.scss')
.pipe(plumber())
.pipe(sass({
outputStyle: 'expanded'
}))
.pipe(postcss(postcssPlugins))
.pipe(rename('ed-grid.css'))
.pipe(gulp.dest('./src/css/'))
})
// Compila páginas internas
gulp.task('pug-dev', () =>
gulp.src('./src/pug/pages/**/*.pug')
.pipe(plumber())
.pipe(data(function () {
return JSON.parse(fs.readFileSync('./src/data/casos-de-exito.json'))
}))
.pipe(pug({
pretty: true,
basedir: './'
}))
.pipe(gulp.dest('./docs'))
)
// Compila páginas internas minificadas
gulp.task('pug-build', () =>
gulp.src('./src/pug/pages/**/*.pug')
.pipe(plumber())
.pipe(data(function () {
return JSON.parse(fs.readFileSync('./src/data/casos-de-exito.json'))
}))
.pipe(pug({
basedir: './'
}))
.pipe(gulp.dest('./docs'))
)
// Compila JavaScript sin minificar
gulp.task('scripts-dev', () =>
browserify('./src/js/index.js')
.transform(babelify, {
global: true // permite importar desde afuera (como node_modules)
})
.bundle()
.on('error', function (err) {
console.error(err)
this.emit('end')
})
.pipe(source('scripts.js'))
.pipe(buffer())
.pipe(minify({
ext: {
src: '-min.js',
min: '.js'
}
}))
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./docs/js'))
)
// Compila JavaScript minificado
gulp.task('scripts-build', () =>
browserify('./src/js/index.js')
.transform(babelify, {
global: true // permite importar desde afuera (como node_modules)
})
.bundle()
.on('error', function (err) {
console.error(err)
this.emit('end')
})
.pipe(source('scripts.js'))
.pipe(buffer())
.pipe(minify({
ext: {
src: '.js',
min: '-min.js'
}
}))
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./docs/js'))
)
// Copia y comprime imágenes
gulp.task('images-build', () => {
gulp.src('./src/img/**/**')
.pipe(imagemin([
imagemin.gifsicle({interlaced: true}),
imagemin.jpegtran({progressive: true}),
imagemin.optipng({optimizationLevel: 5}),
imagemin.svgo()
]))
.pipe(gulp.dest('./docs/assets/img'))
})
// Copia imágenes para desarrollo
gulp.task('images-dev', () => {
gulp.src('./src/img/**/**')
.pipe(gulp.dest('./docs/assets/img'))
})
// Copia html de testing
gulp.task('html', () => {
gulp.src('./test.html')
.pipe(gulp.dest('./docs/'))
})
gulp.task('sitemap', () => {
gulp.src('./docs/**/*.html', {
read: false
})
.pipe(sitemap({
siteUrl: 'https://ed-grid.com' // remplazar por tu dominio
}))
.pipe(gulp.dest('./docs'))
})
gulp.task('cache', () => {
gulp.src('./docs/**/*.html')
.pipe(cachebust({
type: 'timestamp'
}))
.pipe(gulp.dest('./docs'))
})
gulp.task('dev', ['styles-dev', 'pug-dev', 'scripts-dev', 'images-dev', 'html'], () => {
server.init({
server: {
baseDir: './docs'
}
})
gulp.watch('./src/scss/**/**', () => gulp.start('styles-dev'))
gulp.watch('./src/js/**/**', () => gulp.start('scripts-dev', server.reload))
gulp.watch('./src/pug/**/**', () => gulp.start('pug-dev', server.reload))
gulp.watch('./src/data/**/**', () => gulp.start('pug-dev', server.reload))
gulp.watch('./src/md/**/**', () => gulp.start('pug-dev', server.reload))
gulp.watch('./test.html', () => gulp.start('html', server.reload))
gulp.watch('./src/img/**/**', () => gulp.start('images-dev'))
})
// Compila versión CSS para producción
gulp.task('css', ['css-build', 'css-build-min'])
gulp.task('build', ['styles-build', 'pug-build', 'scripts-build', 'images-build', 'cache', 'sitemap'])