1 |
|
2 | var nodeSize = require('../node/size');
|
3 |
|
4 | module.exports = function(bundles){
|
5 | var splitBundles = [];
|
6 | bundles.forEach(function(bundle){
|
7 | var typeToBundle = {};
|
8 |
|
9 | bundle.nodes.forEach(function(node){
|
10 |
|
11 | var buildType = node.load.metadata.buildType || "js";
|
12 |
|
13 | var buildTypeBundle = typeToBundle[buildType];
|
14 | if(!buildTypeBundle) {
|
15 | buildTypeBundle = typeToBundle[buildType] = {
|
16 | size: 0,
|
17 | nodes: [],
|
18 | bundles: bundle.bundles,
|
19 | buildType: buildType
|
20 | };
|
21 | }
|
22 |
|
23 | buildTypeBundle.nodes.push(node);
|
24 | buildTypeBundle.size += nodeSize(node);
|
25 | });
|
26 | for(var buildType in typeToBundle) {
|
27 | splitBundles.push(typeToBundle[buildType]);
|
28 | }
|
29 | });
|
30 | return splitBundles;
|
31 | };
|