-
Notifications
You must be signed in to change notification settings - Fork 139
/
gulpfile.babel.js
132 lines (122 loc) · 2.93 KB
/
gulpfile.babel.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
"use strict";
var _ = require("lodash");
var bs = require("browser-sync").create();
var gulp = require("gulp");
var path = require("path");
var webpack = require("webpack");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var webpackOptions = {
entry: {
app: "./frontend/app.js",
vendor: [
"react",
"react-dom",
"muicss",
"stellar-sdk",
"axios",
"d3",
"fbemitter",
],
},
devtool: "source-map",
resolve: {
root: [path.resolve("frontend"), path.resolve("common")],
modulesDirectories: ["node_modules"],
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
query: { presets: ["es2015", "react"] },
},
{ test: /\.json$/, loader: "json-loader" },
{ test: /\.html$/, loader: "file?name=[name].html" },
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract(
"style-loader",
"css-loader!sass-loader",
),
},
],
},
plugins: [
new webpack.IgnorePlugin(/ed25519/),
new ExtractTextPlugin("style.css"),
],
};
const develop = function (done) {
var options = merge(webpackOptions, {
output: {
filename: "[name].js",
path: "./.tmp",
},
plugins: [new webpack.optimize.CommonsChunkPlugin("vendor", "vendor.js")],
});
var watchOptions = {
aggregateTimeout: 300,
};
var bsInitialized = false;
var compiler = webpack(options);
compiler.purgeInputFileSystem();
compiler.watch(watchOptions, function (error, stats) {
if (!bsInitialized) {
gulp.watch(".tmp/**/*").on("change", bs.reload);
bs.init({
port: 3000,
online: false,
notify: false,
server: "./.tmp",
socket: {
domain: "localhost:3000",
},
});
bsInitialized = true;
}
console.log(
stats.toString({
hash: false,
version: false,
timings: true,
chunks: false,
colors: true,
}),
);
});
};
const build = function (done) {
var options = merge(webpackOptions, {
bail: true,
output: {
// TODO chunkhash
filename: "[name].js", //"[name]-[chunkhash].js",
path: "./dist",
},
plugins: [
new webpack.optimize.CommonsChunkPlugin("vendor", "vendor.js"),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production"),
},
}),
new webpack.optimize.UglifyJsPlugin(),
],
});
var compiler = webpack(options);
compiler.purgeInputFileSystem();
compiler.run(done);
};
function merge(object1, object2) {
return _.mergeWith(object1, object2, function (a, b) {
if (_.isArray(a)) {
return a.concat(b);
}
});
}
gulp.task("develop", develop);
gulp.task("build", build);
gulp.task("default", develop);