Skip to content

Commit

Permalink
Do not deep clone bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mujica committed Sep 29, 2017
1 parent 39f58ee commit b7a2962
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions lib/graph/slim_graph.js
@@ -1,9 +1,10 @@
var omit = require("lodash/omit");
var first = require("lodash/first");
var negate = require("lodash/negate");
var concat = require("lodash/concat");
var assign = require("lodash/assign");
var partial = require("lodash/partial");
var includes = require("lodash/includes");
var cloneDeep = require("lodash/cloneDeep");
var isJavaScriptBundle = require("../bundle/is_js_bundle");
var makeSlimShimNode = require("../node/make_slim_shim_node");
var makeSlimBundleNode = require("../node/make_slim_bundle_node");
Expand Down Expand Up @@ -82,7 +83,7 @@ module.exports = function(options) {
var secondaryBundles = jsBundles.filter(negate(isEntryPointBundle));

// each entry point bundle includes the loader code
entryPointBundles.forEach(function(bundle) {
var slimmedEntryBundles = entryPointBundles.map(function(bundle) {
var mainName = getMainName(bundle);

var sharedBundles = getSharedBundlesOf(
Expand All @@ -92,10 +93,10 @@ module.exports = function(options) {
mainName
);

bundle.nodes = [
var nodes = [
slimConfigNode,
makeSlimShimNode({
nodes: bundle.nodes,
nodes: bundle.nodes.slice(0),
target: options.target,
sharedBundles: sharedBundles,
plugins: !!nonJsBundles.length,
Expand All @@ -105,10 +106,13 @@ module.exports = function(options) {
})
];

return assign({}, omit(bundle, ["nodes"]), {
nodes: nodes
});
});

slimmedBundles = concat(
entryPointBundles,
slimmedEntryBundles,
secondaryBundles.map(partial(toSlimBundle, options.target)),
nonJsBundles
);
Expand Down Expand Up @@ -143,9 +147,9 @@ function getSharedBundlesOf(bundles, mainName) {
}

function toSlimBundle(target, bundle) {
var cloned = cloneDeep(bundle);
cloned.nodes = [makeSlimBundleNode(target, cloned)];
return cloned;
return assign({}, omit(bundle, ["nodes"]), {
nodes: [makeSlimBundleNode(target, bundle)]
});
}

function makeLoaderBundle(nodes) {
Expand Down
2 changes: 1 addition & 1 deletion lib/stream/slim.js
Expand Up @@ -26,7 +26,7 @@ module.exports = function(options) {
* @return {Object} The mutated data
*/
function doSlimGrap(data, options) {
var bundles = cloneDeep(data.bundles);
var bundles = data.bundles.slice(0);

var slimmedBundles = slimGraph({
graph: data.graph,
Expand Down

0 comments on commit b7a2962

Please sign in to comment.