-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.js
84 lines (77 loc) · 1.72 KB
/
compile.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
var webpack = require("webpack");
var argv = require("yargs").argv;
var path = require("path");
var notifier = require("node-notifier");
var compiler = webpack({
entry: {
Handee: './lib/Handee.js',
test: './test/testfile.js',
},
output: {
path: path.join(__dirname, 'bin'),
filename: "[name].js",
library: "[name].js",
libraryTarget: 'umd',
},
resolve: {
extensions: ['', '.js'],
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: [
'es2015',
'stage-2',
'react',
],
plugins: [
'transform-class-properties',
],
},
},
],
},
});
function formatAsset(asset) {
var name = asset.name;
var size = asset.size;
var sizeStr = size + " B";
if (size > 1000) sizeStr = Math.ceil(size / 1000) + " kB";
if (size > 1000000) sizeStr = Math.ceil(size / 1000000) + " MB";
return name + " [" + sizeStr + "]";
}
if (argv.watch) {
compiler.watch({}, function(err, stats) {
if (!err) {
console.log(stats.toString({
colors: true,
chunks: false,
version: false,
}));
var s = stats.toJson();
if (s.errors && s.errors.length) {
notifier.notify({
"title": "ERROR!",
"message": "Check the console for errors",
});
} else {
notifier.notify({
"title": "Build complete",
"message": s.assets.map(formatAsset).join("\n"),
});
}
}
})
} else {
compiler.run(function(err, stats) {
console.log(stats.toString({
colors: false,
chunks: false,
version: false,
}));
});
}