-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
136 lines (119 loc) · 2.65 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
const gulp = require("gulp");
const clean = require("gulp-clean");
const sass = require("gulp-sass")(require("sass"));
// const browserSync = require("browser-sync").create();
const { exec } = require("child_process");
// Removes previous dist
gulp.task("start", () => {
return gulp
.src("./dist", {
allowEmpty: true,
})
.pipe(clean());
});
// Creates js bundle from several js files
gulp.task("bundle", (cb) => {
exec("webpack", (err, msg) => {
console.log(msg || err);
cb();
});
// return webpack(webpackConfig).pipe(gulp.dest("./dist"));
});
// Converts scss to css
gulp.task("scss", () => {
return gulp
.src("./src/**/*.scss", { allowEmpty: true })
.pipe(sass())
.pipe(gulp.dest("./dist"));
});
// Transfers static files
gulp.task("static", () => {
return gulp
.src(["src/**/*", "!src/**/*.ts", "!src/**/*.scss"], { allowEmpty: true })
.pipe(gulp.dest("./dist/"));
});
// Initial ts compile
gulp.task("tsc", (cb) => {
exec("tsc", (err, msg) => {
cb();
});
});
// // Browser Sync
// gulp.task("browser-sync", () => {
// browserSync.init({
// browser: "google-chrome",
// port: 4000,
// server: {
// baseDir: "./dist",
// },
// });
// });
// // Browser Sync live reload
// gulp.task("browser-sync-watch", () => {
// gulp.watch("./dist/styles.css").on("change", browserSync.reload);
// gulp.watch("./dist/app.js").on("change", browserSync.reload);
// gulp.watch("./dist/index.html").on("change", browserSync.reload);
// });
// Watch scss files
gulp.task("watch-scss", () => {
return gulp.watch("./src/**/*.scss", gulp.series("scss"));
});
// Watch static files
gulp.task("watch-static", () => {
return gulp.watch(
["src/**/*", "!src/**/*.ts", "!src/**/*.scss"],
gulp.series("static")
);
});
// Watch ts files
gulp.task("tsc-w", () => {
exec("tsc -w");
});
// Watch tsc files
gulp.task("watch-js", () => {
return gulp.watch("./dist/js/**/*.js", gulp.series("bundle"));
});
gulp.task("server", () => {
const process = exec("nodemon dist/server");
process.stdout.on("data", (msg) => {
console.log(msg);
});
});
gulp.task("remove-source", () => {
return gulp.src(["./dist/**/*.js.map"], { allowEmpty: true }).pipe(clean());
});
gulp.task(
"build",
gulp.series("start", "tsc", "scss", "static", "bundle", "remove-source")
);
// Run all together
gulp.task(
"default",
gulp.series(
"build",
gulp.parallel(
"watch-scss",
"watch-static",
"tsc-w",
"watch-js",
"server"
),
(cb) => cb()
)
);
// Run all together
gulp.task(
"browser",
gulp.series(
"build",
gulp.parallel(
// "browser-sync",
// "browser-sync-watch",
"watch-scss",
"watch-static",
"tsc-w",
"watch-js"
),
(cb) => cb()
)
);