-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
92 lines (86 loc) · 2.27 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
const gulp = require("gulp");
const path = require("path");
const del = require("del");
const gutil = require("gulp-util");
const webpack = require("webpack");
const WebpackDevServer = require("webpack-dev-server");
const webpack_client_config = require("./webpack.config").createConfig;
const server_settings = require("./devenv-settings");
function getWebpackConsoleStats(isProduction) {
return({
colors: true,
chunks: false,
assets: isProduction || false,
assets: true,
timings: true,
modules: false,
hash: false,
version: false
});
}
function printBuildType(name) {
console.log(`Building ${name} for ${isProduction() ? "Production" : "Development"}`)
};
gulp.task("clean", callback => {
del([
"./html/build",
"./html/index.html"
]).then(result => { callback(); });
});
gulp.task("build",
gulp.series(
"clean",
complileClient
)
);
gulp.task("dev",
gulp.series(
"clean",
setDevelopmentEnv,
watchClient
)
);
gulp.task("prod",
gulp.series(
"clean",
setProductionEnv,
complileClient
)
);
gulp.task("default",
gulp.series("dev")
);
function setDevelopmentEnv(callback) {
process.env.NODE_ENV = "development";
callback();
}
function setProductionEnv(callback) {
process.env.NODE_ENV = "production";
callback();
}
function isProduction() {
return process.env.NODE_ENV === "production";
}
function complileClient(callback) {
printBuildType("Client");
webpack(webpack_client_config(!isProduction()), (err, stats) => {
if (err) {
callback(err);
return;
}
console.log(stats.toString(getWebpackConsoleStats(isProduction())));
callback();
})
};
function watchClient() {
const compiler = webpack(webpack_client_config(!isProduction()));
const server = new WebpackDevServer(compiler, {
contentBase: path.resolve(__dirname, "html"),
publicPath: "/",
disableHostCheck: true,
hot: true,
stats:getWebpackConsoleStats(isProduction()),
//headers: { "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Credentials": "true" }
});
server.listen(server_settings.clientDevPort, () => {});
};