1 | var webpack = require(process.cwd() + '/node_modules/webpack');
|
2 |
|
3 | try {
|
4 | var entries = require(process.cwd() + '/build.json');
|
5 | } catch (e) {
|
6 | var entries = {main:{}};
|
7 | }
|
8 |
|
9 | var config = Object.keys(entries).map(function(entry) {
|
10 | delete require.cache[require.resolve(process.cwd())];
|
11 | var child = require(process.cwd()).builder;
|
12 | child.name = entry;
|
13 | var main = child.entry.main;
|
14 | delete child.entry.main;
|
15 | child.entry[entry] = main;
|
16 | child.plugins.push(new webpack.DefinePlugin(encode(entries[entry])));
|
17 | return child;
|
18 | });
|
19 |
|
20 | function encode(obj) {
|
21 | for (k in obj) {
|
22 | obj[k] = JSON.stringify(obj[k]);
|
23 | }
|
24 | return obj;
|
25 | }
|
26 |
|
27 | function handleFatalError(err) {
|
28 | console.error(err.stack);
|
29 | process.exit(1);
|
30 | }
|
31 |
|
32 | function handleSoftErrors(errors) {
|
33 | errors.forEach(function(err) {
|
34 | console.error(err.stack || err);
|
35 | });
|
36 | process.exit(1);
|
37 | }
|
38 |
|
39 | webpack(config, function(err, stats) {
|
40 | if (err) return handleFatalError(err);
|
41 | var jsonStats = stats.toJson();
|
42 | if (jsonStats.errors.length > 0) return handleSoftErrors(jsonStats.errors);
|
43 | console.log(stats.toString({
|
44 | "cached": false,
|
45 | "cachedAssets": false,
|
46 | "modules": true,
|
47 | "chunks": false,
|
48 | "reasons": false,
|
49 | "errorDetails": false,
|
50 | "chunkOrigins": false,
|
51 | "exclude": [
|
52 | "node_modules",
|
53 | "bower_components",
|
54 | "jam",
|
55 | "components"
|
56 | ]
|
57 | }));
|
58 | process.exit(0);
|
59 | });
|