1 | var omit = require("lodash/omit");
|
2 | var through = require("through2");
|
3 | var assign = require("lodash/assign");
|
4 | var slimGraph = require("../graph/slim_graph");
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | module.exports = function(options) {
|
10 | var opts = options != null ? options : {};
|
11 |
|
12 | return through.obj(function(data, enc, next) {
|
13 | try {
|
14 | next(null, doSlimGrap(data, opts));
|
15 | } catch (err) {
|
16 | next(err);
|
17 | }
|
18 | });
|
19 | };
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | function doSlimGrap(data, options) {
|
28 | var bundles = data.bundles.slice(0);
|
29 |
|
30 | var slimmedBundles = slimGraph({
|
31 | graph: data.graph,
|
32 | mains: data.mains,
|
33 | bundles: bundles,
|
34 | target: options.target,
|
35 | baseUrl: data.loader.baseURL,
|
36 | slimConfig: data.loader.slimConfig,
|
37 | splitLoader: data.options.splitLoader,
|
38 | bundlesPath: data.configuration.bundlesPath,
|
39 | configMain: data.loader.configMain || "package.json!npm",
|
40 | progressiveBundles: getProgressiveBundles(data.loader, data.graph)
|
41 | });
|
42 |
|
43 | return assign(
|
44 | {},
|
45 | omit(data, ["bundles"]),
|
46 | { bundles: slimmedBundles }
|
47 | );
|
48 | }
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | function getProgressiveBundles(loader, graph) {
|
58 | var config = loader.__loaderConfig || {};
|
59 | var configBundle = config.bundle || [];
|
60 |
|
61 | return loader.bundle.map(function(name, index) {
|
62 | return {
|
63 | id: graph[name].load.uniqueId,
|
64 |
|
65 |
|
66 |
|
67 | name: configBundle[index] || name
|
68 | };
|
69 | });
|
70 | }
|