From 04a8e07fbba5c9cf9b5c4276de969d8a8ef78b9f Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Tue, 15 Oct 2019 10:40:20 +0200 Subject: [PATCH] Optimize exports of the wp/compose package Adds `sideEffects:false` to `package.json` so that unused exports can be optimized away by the bundler. Moves the `compose` definition (i.e., reexport from Lodash) to its own module, so that we don't pull in Lodash just by importing something from `@wordpress/compose`. After this patch, one needs to import `compose` explicitly to trigger the Lodash import. --- packages/compose/package.json | 1 + packages/compose/src/higher-order/compose.js | 14 ++++++++++++++ packages/compose/src/index.js | 16 ++-------------- 3 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 packages/compose/src/higher-order/compose.js diff --git a/packages/compose/package.json b/packages/compose/package.json index 827a0afb46eff7..acd8a54224fde0 100644 --- a/packages/compose/package.json +++ b/packages/compose/package.json @@ -21,6 +21,7 @@ "main": "build/index.js", "module": "build-module/index.js", "react-native": "src/index", + "sideEffects": false, "dependencies": { "@babel/runtime": "^7.4.4", "@wordpress/element": "file:../element", diff --git a/packages/compose/src/higher-order/compose.js b/packages/compose/src/higher-order/compose.js new file mode 100644 index 00000000000000..a166387821e7b3 --- /dev/null +++ b/packages/compose/src/higher-order/compose.js @@ -0,0 +1,14 @@ +/** + * External dependencies + */ +import { flowRight as compose } from 'lodash'; + +/** + * Composes multiple higher-order components into a single higher-order component. Performs right-to-left function + * composition, where each successive invocation is supplied the return value of the previous. + * + * @param {...Function} hocs The HOC functions to invoke. + * + * @return {Function} Returns the new composite function. + */ +export default compose; diff --git a/packages/compose/src/index.js b/packages/compose/src/index.js index 9ea31b2d351aba..ab1ecf3564edbe 100644 --- a/packages/compose/src/index.js +++ b/packages/compose/src/index.js @@ -1,20 +1,8 @@ -/** - * External dependencies - */ -import { flowRight } from 'lodash'; - // Utils export { default as createHigherOrderComponent } from './utils/create-higher-order-component'; -/** - * Composes multiple higher-order components into a single higher-order component. Performs right-to-left function - * composition, where each successive invocation is supplied the return value of the previous. - * - * @param {...Function} hocs The HOC functions to invoke. - * - * @return {Function} Returns the new composite function. - */ -export { flowRight as compose }; +// Compose helper (aliased flowRight from Lodash) +export { default as compose } from './higher-order/compose'; // Higher-order components export { default as ifCondition } from './higher-order/if-condition';