-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
56 lines (43 loc) · 1.53 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
const beepbeep = require("beepbeep");
const gulp = require("gulp");
const nodeExternals = require("webpack-node-externals");
const webpackStream = require("webpack-stream");
gulp.task("js-server", function() { return js_server({uglify: true}); });
gulp.task("js-client", function() { return js_client({uglify: true}); });
gulp.task("js", ["js-server", "js-client"]);
gulp.task("js-server-watch", function() { return js_server({watch: true}); });
gulp.task("js-client-watch", function() { return js_client({watch: true}); });
gulp.task("js-watch", ["js-server-watch", "js-client-watch"]);
function errorHandler(error) {
console.log(error.toString());
beepbeep();
this.emit("end");
}
function js(options) {
const webpackConfig = Object.assign({
resolve: {extensions: ["", ".ts", ".js"]},
module: {loaders: [{test: /\.ts$/, loader: "ts-loader", exclude: /node_modules/}]},
plugins: options.uglify ? [new webpackStream.webpack.optimize.UglifyJsPlugin()] : [],
}, options, { src: null, dest: null, uglify: null});
return gulp
.src(options.src)
.pipe(webpackStream(webpackConfig))
.on("error", errorHandler)
.pipe(gulp.dest(options.dest));
}
function js_server(options) {
return js(Object.assign({
src: "./src/ts/server/index.ts",
dest: "./bin/",
output: {filename: "server.js"},
target: "node",
externals: [nodeExternals()]
}, options));
}
function js_client(options) {
return js(Object.assign({
src: "./src/ts/client/index.ts",
dest: "./public/res/",
output: {filename: "bundle.js", publicPath: "/res/"}
}, options));
}