-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
238 lines (219 loc) · 5.48 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
import { src, dest, parallel, series, watch } from "gulp";
import plumber from "gulp-plumber";
import pug from "gulp-pug";
import browserSync from "browser-sync";
import sass from "gulp-sass";
import postcss from "gulp-postcss";
import cssnano from "cssnano";
import browserify from "browserify";
import babelify from "babelify";
import source from "vinyl-source-stream";
import sourcemaps from "gulp-sourcemaps";
import buffer from "vinyl-buffer";
import uglify from "gulp-uglify";
import imagemin from "gulp-imagemin";
import sitemap from "gulp-sitemap";
import cachebust from "gulp-cache-bust";
import htmlmin from "gulp-htmlmin";
import humans from "gulp-humans";
import robots from "gulp-robots";
const server = browserSync.create();
const postcssPlugins = [
cssnano({
core: true,
zindex: false,
autoprefixer: {
add: true,
browsers: "> 1%, last 2 versions, Firefox ESR, Opera 12.1",
},
}),
];
const sitemapTask = () => {
return src("./public/**/*.html", { read: false })
.pipe(
sitemap({
siteUrl: "https://xizuth-iot.web.app/",
})
)
.pipe(dest("./public"));
};
const jsTask = () => {
return browserify({
extensions: [".js"],
entries: ["src/js/main.js"],
debug: true,
})
.transform("babelify", {
// https://babeljs.io/docs/en/env/
presets: ["@babel/preset-env"],
})
.bundle()
.pipe(source("main.min.js"))
.on("error", (e) => {
console.log("error Source"), e;
})
.pipe(buffer())
.on("error", (e) => {
console.log("error en Buffer"), e;
})
.pipe(sourcemaps.init())
.on("error", (e) => {
console.log("error en sourcemaps"), e;
})
.pipe(uglify())
.on("error", (e) => {
console.log("error en uglify"), e;
})
.pipe(sourcemaps.write("./maps"))
.on("error", (e) => {
console.log("error en write sourcemaps"), e;
})
.pipe(dest("public/js/"))
.on("error", (e) => {
console.log("error en dest js"), e;
});
};
const pugTask = () => {
return src("./src/views/pages/**.pug")
.pipe(plumber())
.pipe(
pug({
pretty: false,
basedir: "./src/views",
})
)
.pipe(dest("./public"));
};
const sassTask = () => {
return src("./src/sass/style.scss")
.pipe(sass())
.on("error", (e) => {
console.log("error en la compilacion SASS", e);
})
.pipe(postcss(postcssPlugins))
.on("error", (e) => {
console.log("error en la compilacion POST CSS"), e;
})
.pipe(dest("./public/css"))
.pipe(server.stream());
};
const imgTask = () => {
return src("./src/assets/img/**")
.pipe(
imagemin([
imagemin.gifsicle({ interlaced: true }),
imagemin.jpegtran({ progressive: true }),
imagemin.optipng({ optimizationLevel: 5 }),
imagemin.svgo(),
])
)
.pipe(dest("./public/assets/img"));
};
const initServer = () => {
server.init({
server: {
baseDir: "./public",
},
});
console.log("inicia el servidor");
};
const fontTask = () => {
return src("src/assets/fonts/**").pipe(dest("public/assets/fonts"));
};
const humanTask = () => {
return src("public/index.html")
.pipe(
humans({
team: [
{
"Original developer": "Alejandro Leyva",
Twitter: "@jalm_x",
Github: "@jalmx",
},
{
Maintainer: "Xizuth Inc",
Github: "@xizuth_tech",
},
],
thanks: ["Node (@nodejs on Twitter)", "Gulp (@gulpjs on Twitter)"],
site: [
"Standards: HTML5, CSS, ES6",
"Components: Pug, SASS, Google Fonts, Material Design Icons",
"Software: Visual Studio Code",
],
note: "Built with love by Alejandro Leyva.",
})
)
.pipe(dest("public/"));
};
const robotTask = () => {
return src("./public/index.html")
.pipe(
robots({
useragent: "*",
allow: ["/"],
disallow: ["cgi-bin/"],
})
)
.pipe(dest("public/"));
};
const faviconTask = () => {
return src("src/assets/favicon/**").pipe(dest("public/assets/favicon"));
};
const cacheTask = () => {
return src("./public/**/**.html")
.pipe(
cachebust({
type: "timestamp",
})
)
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(dest("./public"));
};
exports.fonts = fontTask;
exports.favicon = faviconTask;
exports.humans = humanTask;
exports.robot = robotTask;
exports.cache = cacheTask;
exports.pug = pugTask;
exports.sitemap = sitemapTask;
exports.imgs = imgTask;
exports.sass = sassTask;
exports.js = jsTask;
exports.build = series(
pugTask,
imgTask,
sassTask,
jsTask,
fontTask,
humanTask,
robotTask,
sitemapTask,
faviconTask,
cacheTask,
initServer
);
exports.default = series(pugTask, sassTask, jsTask, initServer);
const watcher = watch(["./src"]);
watcher.on("all", (path, stats) => {
if (stats.indexOf("sass") > 0) {
sassTask();
console.log("actualiza css");
} else if (stats.indexOf("views") > 0) {
pugTask();
console.log("actualiza html");
server.reload();
} else if (stats.indexOf("js")) {
jsTask();
console.log("actualiza js");
server.reload();
}
});
// if launch a Error like
// System limit for number of file watchers reached, watch 'src'
// solution for linux:
// sudo sysctl -w fs.inotify.max_user_watches=100000
// in the file /etc/sys.conf put:
// fs.inotify.max_user_watches = 100000
// create /etc/sysctl.d/10-user-watches.conf with
// fs.inotify.max_user_watches = 100000