forked from javascript-tutorial/server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.js
executable file
·79 lines (65 loc) · 1.64 KB
/
webpack.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
let webpack = require('webpack');
let notifier = require('node-notifier');
module.exports = async function() {
await new Promise((resolve, reject) => {
let config = require('config').webpack();
webpack(config, function(err, stats) {
if (!err) {
// errors in files do not stop webpack watch
// instead, they are gathered, so I get the first one here (if no other)
let jsonStats = stats.toJson();
err = jsonStats.errors[0];
}
if (err) {
notifier.notify({
message: err
});
console.log(err);
if (!config.watch) reject(err);
return;
}
/*
Log profile
console.log( stats.toJson().modules.map(function(mod) {
return {
identifier: mod.identifier,
name: mod.name,
profile: mod.profile
};
}) );
*/
/*
For webpack analyse
require('fs').writeFileSync('/tmp/webpack.json', JSON.stringify(stats.toJson()));
*/
console.log('[webpack]', stats.toString({
hash: false,
version: false,
timings: true,
assets: true,
chunks: false,
modules: false,
cached: true,
colors: true
}));
/*
Log profile and all details
console.log('[webpack]', stats.toString({
hash: false,
version: false,
timings: true,
assets: true,
chunks: true,
chunkModules: true,
modules: true,
cached: true,
colors: true,
profile: true
}));
*/
if (!config.watch) {
resolve();
}
});
});
};