vasturiano/force-graph

Replace lodash.throttle with lodash-es package to avoid tree shaking optimization warning

gabynevada opened this issue · 2 comments

I'm currently using this awesome package in an angular app, the use of lodash.throttle package is throwing a warning about common js imports and the impact on tree shaking and optimizations.

The warning for context:

Warning: .{{projectPath}}/node_modules/force-graph/dist/force-graph.mjs depends on 'lodash.throttle'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

This issue can be easily resolved by utilizing lodash-es instead of lodash.throttle. The lodash githug page currently recommends lodash-es for smaller bundle sizes, and it's the same lodash library exported as ES modules.

The change would be:

  1. Replace lodash.throttle for lodash-es in package.json
yarn add lodash-es
yarn remove lodash.throttle
  1. Replace throttle import in force-graph.js

From:

import throttle from 'lodash.throttle';

To:

import { throttle } from 'lodash-es';

In the end it will result in the same function you're using now but will prevent the CommonJS import and any possible optimization problems it may cause.

If you accept PRs I could work on it if needed, thanks!

@gabynevada sounds good. Yes, please open a PR with the intended changes. 👍

Pull request is up at #315. Any feedback is welcome.

Thanks!