Closed kwhsiung closed 4 years ago
Is the scenario that we import both lodash and lodash-es packages in some of our js files. So we should alias lodash-es to lodash, to prevent webpack bundling both lodash-es and lodash?
Yup! Specifically, the scenario is āIām using lodash
but my dependency a
is using lodash-es
ā. Or vice versa.
If 1. is true, why we are not alias lodash to lodash-es but alias lodash-es to lodash, Is the consideration is about lodash-fp? Because the bundle size that lodash-fp + lodash-es > lodash-fp + lodash.
Hmm, thatās a good question. I think some configurations had compatibility issues when aliasing lodash
to lodash-es
, but I canāt really remember. (Never knew about the bundle size aspect of lodash/fp
though.) Iāll add more info if I find anything!
RE: why not alias lodash
to lodash-es
I conducted a quick investigation here, and I've found that using lodash-es
is the least performant if using WP4 (fine in WP5).
Experiment | Output size (kB) |
---|---|
Tree-shaking w/ babel-plugin-lodash & lodash-webpack-plugin | 19.7 |
Tree-shaking w/ lodash-es | 120.8 |
Tree-shaking w/ babel-plugin-lodash | 121.2 |
Importing specific lodash utils by path (Baseline) | 121.5 |
Tree-shaking w/ lodash-es using WP4 | 135.5 |
Thanks for curating these useful tips. š But I have question about "Alias
lodash-es
tolodash
"I just wondering the scenario that "Lodash will be bundled twice".
lodash
andlodash-es
packages in some of our js files. So we should aliaslodash-es
tolodash
, to prevent webpack bundling bothlodash-es
andlodash
?lodash
tolodash-es
but aliaslodash-es
tolodash
, Is the consideration is aboutlodash-fp
? Because the bundle size thatlodash-fp
+lodash-es
>lodash-fp
+lodash
.