-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
96 lines (89 loc) · 2.37 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
const gulp = require("gulp"),
webpack = require("webpack"),
fs = require("fs"),
del = require("del"),
archiver = require("archiver"),
nodemon = require("nodemon"),
express = require("express"),
moment = require("moment"),
chalk = require("chalk"),
base = require("./config/base.js"),
develop = require("./config/develop.js"),
product = require("./config/product.js"),
webpackDevServer = require("webpack-dev-server"),
webpackDevMiddleware = require("webpack-dev-middleware"),
webpackHotMiddleware = require("webpack-hot-middleware");
// base config
const Uri = base.client.uri;
const Port = base.client.port;
// config for devServer
const devServerConfig = {
publicPath: Uri,
contentBase: "./sources",
watchContentBase: true,
hot: true,
lazy: false,
stats: {
colors: true
},
};
/** gulp default */
gulp.task("default", () => {
nodemon({
script: "./server/app.js",
watch: ["./server/**/*.js"],
});
var app = express();
const compiler = webpack(develop);
app.use(webpackDevMiddleware(compiler, devServerConfig));
app.use(webpackHotMiddleware(compiler));
app.listen(Port, () => {
console.info(
chalk.green.bgBlue("webpack-dev-server starting on http://localhost:" + Port + Uri)
);
});
});
/** gulp build */
gulp.task("build", () => {
const compiler = webpack(product);
compiler.run((err, stats) => {
if (err) {
console.error(err);
return;
};
console.info(stats.toString({
chunks: false,
colors: true
}));
});
});
/** gulp release */
gulp.task("release", () => {
const timestamp = moment().format("YYYY-MM-DD HH.mm.ss");
!fs.existsSync("release") ? fs.mkdirSync("release") : {};
const output = fs.createWriteStream("./release/release " + timestamp + ".zip");
const archive = archiver("zip", {
prefix: "release"
});
archive.pipe(output);
archive.directory("./build", false);
archive.finalize();
});
/** gulp clean */
gulp.task("clean", () => {
del(["./release/**/*", "./build/**/*"]);
});
/** gulp test */
gulp.task("test", function () {
nodemon({
script: "./server/app.js",
watch: ["./server/*.js"],
});
const compiler = webpack(develop);
const server = new webpackDevServer(compiler, devServerConfig);
server.listen(Port, () => {
console.info(
chalk.green.bgBlue("webpack-dev-server starting on http://localhost:" + Port + Uri)
);
});
});