diff --git a/lib/graph/slim_graph.js b/lib/graph/slim_graph.js index 6ed630cb..db1d0d9a 100644 --- a/lib/graph/slim_graph.js +++ b/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"); @@ -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( @@ -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, @@ -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 ); @@ -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) { diff --git a/lib/stream/slim.js b/lib/stream/slim.js index eed1fa43..8123f0d6 100644 --- a/lib/stream/slim.js +++ b/lib/stream/slim.js @@ -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,