astar-typescript icon indicating copy to clipboard operation
astar-typescript copied to clipboard

Review Lodash dependency

Open cjke opened this issue 4 years ago • 1 comments

Hello, cool library!

Would it be possible to review the approach to importing lodash? I've seen the PR that recommended the es approach, and agree that was not the way to go.

I think there are two simple solutions:

Option 1. Import with a slash as recommended at the end of the official docs: https://lodash.com/per-method-packages For example, in astar-finder.ts:

import { minBy, remove } from 'lodash';

Becomes

import minBy from 'lodash/minBy';
import remove from 'lodash/remove';

This should dramatically cut down the bundle size.

Option 2. Alternatively, perhaps set lodash as a peer dependency? At the moment, if I too use lodash, I end up with a double sized bundle, which would be removed when set as a peer. (but I still prefer option 2, or maybe even both)

Example of a project using lodash + astar-typescript using lodash 😱 image

cjke avatar Dec 01 '20 11:12 cjke

Hello @cjke

Thank you for your input. It might be that I am going to rewrite the core of the library and maybe not use lodash.js anymore. I am not sure though, when this is going to happen.

Option 1 sounds reasonable.

I have never used peerDependencies, but I believe that this will not work. If I add lodash.js as a peerDependencies I will not be able to access it from my library. See this article:

https://classic.yarnpkg.com/blog/2018/04/18/dependencies-done-right --> The peerDependencies object guarantees that, for each entry, any package that requires you (...)

Keep you updated.

digitsensitive avatar Dec 13 '20 21:12 digitsensitive