Register lodash as dependency to externalize it #1844
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does it do?
I noticed that the dist files of the design system package contain the entire lodash source.
See: https://www.npmjs.com/package/@strapi/design-system/v/2.0.0-rc.14?activeTab=code
The design-system package uses lodash directly in extendTheme.ts but doesn't list this as a dependency in package.json. lodash happens to be present because it is a sub-sub-subdependency:
By making it a direct dependency, vite will not bundle it in the dist files. Besides that, it is more correct to not rely on sub-dependencies.
Why is it needed?
When investigating the dist code of the strapi-plugin-navigation module I noticed that it contains the entire lodash code. I investigated this and it lead to the conclusion that it is actually the design-system package that provides this.
See VirtusLab-Open-Source/strapi-plugin-navigation#509
How to test it?
Build the design-system package before and after this change and observe the file size decrease.
It may be the case that there are more dependencies of the code that could be externalized