-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
97 lines (82 loc) · 2.28 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
var gulp = require("gulp");
var tsify = require("tsify");
var tslint = require("gulp-tslint");
var source = require("vinyl-source-stream");
var browserify = require("browserify");
var browserSync = require('browser-sync').create();
var paths = {
ts: [
"src/**/*.ts",
"src/**/*.tsx"
],
entries: ["src/main.tsx"],
vendors: [
"react",
"react-dom"
],
html: ["src/*.html"],
styles: ["src/styles/*.css"],
output: {
dist: "dist",
html: "dist/*.html",
styles: "dist/styles"
}
};
gulp.task("lint", function() {
return gulp.src(paths.ts)
.pipe(tslint({
formatter: "verbose"
}))
.pipe(tslint.report());
});
gulp.task("vendor", function () {
var browse = browserify({
debug: true
});
paths.vendors.forEach(lib => {
browse.require(lib);
});
return browse
.bundle()
.pipe(source("vendor.js"))
.pipe(gulp.dest(paths.output.dist));
});
gulp.task("app", function () {
return browserify({
debug: true,
entries: paths.entries,
})
.plugin(tsify)
.external(paths.vendors)
.bundle()
.pipe(source("app.js"))
.pipe(gulp.dest(paths.output.dist))
.pipe(browserSync.reload({ stream: true }));
});
gulp.task("html", function () {
return gulp.src(paths.html)
.pipe(gulp.dest(paths.output.dist));
});
gulp.task("styles", function () {
return gulp.src(paths.styles)
.pipe(gulp.dest(paths.output.styles))
.pipe(browserSync.reload({ stream: true }));
});
gulp.task("build", gulp.parallel(gulp.series("lint", "app"), "vendor"));
gulp.task("watch", function() {
gulp.watch(paths.ts, gulp.series("lint", "app"));
gulp.watch(paths.html, gulp.series("html"));
gulp.watch(paths.styles, gulp.series("styles"));
});
gulp.task('serve', function () {
browserSync.init({
server: {
baseDir: paths.output.dist
}
});
gulp.watch(paths.ts, gulp.series("lint", "app"));
gulp.watch(paths.html, gulp.series("html"));
gulp.watch(paths.styles, gulp.series("styles"));
gulp.watch(paths.output.html).on('change', browserSync.reload);
});
gulp.task("default", gulp.parallel("build", "html", "styles"));