forked from bernatmv/phaserito
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
107 lines (95 loc) · 3.06 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
/**
* Based on the work of
* Nestor Hernandez Ojeda (Phasersito)
*/
var gulp = require("gulp");
var gutil = require("gulp-util");
var zip = require('gulp-zip');
var localtunnel = require('localtunnel');
var path = require("path");
var runSequence = require('run-sequence');
var webpack = require("webpack");
var WebpackDevServer = require("webpack-dev-server");
// WebPack configuration
var webpackConfig = require("./webpack.config.js");
gulp.task("default", ["development"]);
gulp.task("build", function() {
runSequence('build-game');
});
gulp.task("build-game", function(callback) {
var myConfig = Object.create(webpackConfig);
myConfig.plugins = myConfig.plugins.concat(
new webpack.DefinePlugin({
"process.env": {
"NODE_ENV": JSON.stringify("production")
}
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin()
);
webpack(myConfig, function(err, stats) {
if (err) throw new gutil.PluginError("webpack:build", err);
gutil.log("[webpack:build]", stats.toString({
colors: true
}));
callback();
});
});
gulp.task("development", function() {
runSequence(['dev-server']);
});
gulp.task("dev-server", function(callback) {
var myConfig = Object.create(webpackConfig);
myConfig.devtool = "eval";
myConfig.debug = true;
myConfig.entry.vendor.push("phaser-debug");
new WebpackDevServer(webpack(myConfig), {
contentBase: path.join(__dirname, "./build"),
stats: {
colors: true
}
}).listen(8080, "localhost", function(err) {
if (err) throw new gutil.PluginError("webpack-dev-server", err);
gutil.log("[dev-server]", "http://localhost:8080/ -> Root");
gutil.log("[dev-server]", "http://localhost:8080/webpack-dev-server/ -> with LiveReload");
});
});
gulp.task("serve-ie9", function(callback) {
var myConfig = Object.create(webpackConfig);
myConfig.devtool = "eval";
myConfig.debug = true;
new WebpackDevServer(webpack(myConfig), {
contentBase: path.join(__dirname, "./build"),
stats: {
colors: true
}
}).listen(8080, "0.0.0.0", function(err) {
if (err) throw new gutil.PluginError("webpack-dev-server", err);
gutil.log("[dev-server]", "http://localhost:8080/ -> Root");
gutil.log("[dev-server]", "http://localhost:8080/webpack-dev-server/ -> with LiveReload");
});
});
gulp.task("localtunnel", function(callback) {
localtunnel(8080, function(err, tunnel) {
if (err) throw new gutil.PluginError("localtunnel", err);
var myConfig = Object.create(webpackConfig);
myConfig.devtool = "eval";
myConfig.debug = true;
myConfig.entry.vendor.push("phaser-debug");
new WebpackDevServer(webpack(myConfig), {
contentBase: path.join(__dirname, "./build"),
stats: {
colors: true
}
}).listen(8080, "localhost", function(err) {
if (err) throw new gutil.PluginError("webpack-dev-server", err);
gutil.log("[localtunnel]", tunnel.url + " -> Root");
gutil.log("[localtunnel]", tunnel.url + "/webpack-dev-server/ -> with LiveReload");
});
});
});
gulp.task("cocoon", ["build"], function(callback) {
return gulp.src('./build/**/*')
.pipe(zip('dist.zip'))
.pipe(gulp.dest('./build'));
});