Skip to content

Commit 9399332

Browse files
authored
chore: use lodash-es to improve bundle size (#4072)
* chore: use lodash-es to improve bundle size * use lodash plugin always * add comments
1 parent 26daf99 commit 9399332

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

.babel-preset.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,20 @@ const plugins = [
3131
},
3232
],
3333
// Plugins that allow to reduce the target bundle size
34+
35+
// `babel-plugin-lodash` is required for all kinds of modules to simplify the resolution of
36+
// modules and avoid modules that prevent tree-shaking:
37+
// https://github.com/lodash/lodash/issues/4119
3438
'lodash',
39+
// CJS modules are not tree-shakable in any bundler by default
40+
// https://github.com/formium/tsdx#using-lodash
41+
(isESBuild || isUMDBuild) && [
42+
'babel-plugin-transform-rename-import',
43+
{
44+
replacements: [{ original: 'lodash', replacement: 'lodash-es' }],
45+
},
46+
],
47+
3548
'transform-react-handled-props',
3649
[
3750
'transform-react-remove-prop-types',

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"clsx": "^1.1.1",
7575
"keyboard-key": "^1.1.0",
7676
"lodash": "^4.17.19",
77+
"lodash-es": "^4.17.15",
7778
"prop-types": "^15.7.2",
7879
"react-is": "^16.8.6",
7980
"react-popper": "^1.3.7",
@@ -105,6 +106,7 @@
105106
"babel-plugin-lodash": "^3.3.4",
106107
"babel-plugin-transform-react-handled-props": "^2.1.0",
107108
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
109+
"babel-plugin-transform-rename-import": "^2.3.0",
108110
"babel-plugin-universal-import": "^2.0.2",
109111
"chai": "^4.2.0",
110112
"chai-enzyme": "^1.0.0-beta.1",

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2798,6 +2798,11 @@ babel-plugin-transform-regenerator@^6.22.0:
27982798
dependencies:
27992799
regenerator-transform "^0.10.0"
28002800

2801+
babel-plugin-transform-rename-import@^2.3.0:
2802+
version "2.3.0"
2803+
resolved "https://registry.yarnpkg.com/babel-plugin-transform-rename-import/-/babel-plugin-transform-rename-import-2.3.0.tgz#5d9d645f937b0ca5c26a24b2510a06277b6ffd9b"
2804+
integrity sha512-dPgJoT57XC0PqSnLgl2FwNvxFrWlspatX2dkk7yjKQj5HHGw071vAcOf+hqW8ClqcBDMvEbm6mevn5yHAD8mlQ==
2805+
28012806
babel-plugin-transform-runtime@^6.23.0:
28022807
version "6.23.0"
28032808
resolved "https://registry.yarnpkg.com/babel-plugin-transform-runtime/-/babel-plugin-transform-runtime-6.23.0.tgz#88490d446502ea9b8e7efb0fe09ec4d99479b1ee"
@@ -8607,6 +8612,11 @@ locate-path@^5.0.0:
86078612
dependencies:
86088613
p-locate "^4.1.0"
86098614

8615+
lodash-es@^4.17.15:
8616+
version "4.17.15"
8617+
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.15.tgz#21bd96839354412f23d7a10340e5eac6ee455d78"
8618+
integrity sha512-rlrc3yU3+JNOpZ9zj5pQtxnx2THmvRykwL4Xlxoa8I9lHBlVbbyPhgyPMioxVZ4NqyxaVVtaJnzsyOidQIhyyQ==
8619+
86108620
lodash._basecopy@^3.0.0:
86118621
version "3.0.1"
86128622
resolved "https://registry.yarnpkg.com/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz#8da0e6a876cf344c0ad8a54882111dd3c5c7ca36"

0 commit comments

Comments
 (0)