-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
91 lines (77 loc) · 2.42 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
const path = require("path");
const gulp = require('gulp');
const browserify = require("browserify");
const tsify = require("tsify");
const babelify = require("babelify");
const vinyl = require("vinyl-source-stream");
const buffer = require('gulp-buffer');
const concat = require('gulp-concat');
const glob = require('glob');
const watchify = require("watchify");
const projectRoot = path.resolve(__dirname);
const clientRootDir = path.join(projectRoot, "src/client");
const clientConfig = {
"baseDir": clientRootDir
}
function buildClient(){
const option = {
"basedir": path.join(clientConfig.baseDir, "src"),
"paths": [path.join(clientConfig.baseDir, "src")],
"debug": true,
"entries": ["index.ts", glob.sync("components/**/*.ts")]
}
return browserify(glob.sync(path.join(projectRoot,"src/client/src/**/*.ts")), option)
.plugin(tsify, {"target": "es6", "project": "src/client"})
.transform(babelify, {
"presets": [
["@babel/preset-env", {"targets": {}}]
],
"extensions": [".js", ".ts"],
"global": true
}
)
.bundle()
.pipe(vinyl("client.js"))
.pipe(buffer())
.pipe(concat('client.js'))
.pipe(gulp.dest("src/server/static/js"));
}
function watchClient(){
const option = {
"paths": [path.join(clientConfig.baseDir, "src")],
"debug": true,
"entries": ["src/client/src/index.ts"],
"cache": {},
"packageCache": {},
};
const client_bro = makeBro(glob.sync("src/client/src/**/*.ts"), option);
const update = ()=>{
return client_bro
.bundle()
.on('error', (err)=>{ console.error(err)})
.pipe(vinyl('client.js'))
.pipe(gulp.dest("src/server/static/js"))
}
client_bro.on('update', update);
return update();
}
function makeBro(files, option){
const bro = browserify(files, option);
bro.plugin(watchify, { "delay": 1000, "ignoreWatch": ['**/node_modules/**']});
bro.plugin(tsify, { "target": "es6", "project": "src/client"});
bro.transform(babelify, {
"presets": [
["@babel/preset-env", {targets: {}}]
],
"extensions": ['.js','.ts'],
"global": true }
);
bro.on('time', (time) => {
const time_obj = new Date()
const current_time = `${time_obj.getHours()}:${time_obj.getMinutes()}:${time_obj.getSeconds()}`;
console.log(`[${current_time}] Updated it takes ${time}ms`);
})
return bro;
}
exports.buildClient = buildClient;
exports.watchClient = watchClient;