Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register lodash as dependency to externalize it #1844

Merged
merged 1 commit into from
Feb 3, 2025

Conversation

jorrit
Copy link
Contributor

@jorrit jorrit commented Jan 29, 2025

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
image

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:

> npm ls lodash
[email protected] .\strapi-design-system
`-- @strapi/[email protected] -> .\packages\design-system
  `-- @strapi/[email protected]
    `-- [email protected]
      `-- [email protected]

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

Copy link

vercel bot commented Jan 29, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
design-system ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 3, 2025 9:30am

@HichamELBSI
Copy link
Collaborator

@jorrit Thanks for your contribution, in order to merge the PR, you will need to generate changeset. You can run yarn release:add to generate it. Feel free to follow the contributing guide.

@jorrit
Copy link
Contributor Author

jorrit commented Jan 31, 2025

My apologies for not following the guidelines. I'll update the PR after the weekend.

Copy link

changeset-bot bot commented Feb 3, 2025

🦋 Changeset detected

Latest commit: 1b5a2d0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@strapi/design-system Patch
@strapi/ui-primitives Patch
@strapi/icons Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jorrit
Copy link
Contributor Author

jorrit commented Feb 3, 2025

@HichamELBS: the commit has been updated. I found a couple of additional improvements using the depcheck tool.

Without this change, the dist files include the entire lodash source and some Radix UI utilities.
Also removes a dependency from @strapi/ui-primitives that wasn't used.
Copy link
Collaborator

@HichamELBSI HichamELBSI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@HichamELBSI HichamELBSI added pr: chore This PR contains chore tasks (cleanups, configs, tooling...) source: dependencies relates to dependencies within the repo labels Feb 3, 2025
@HichamELBSI HichamELBSI merged commit 09dc2ec into strapi:main Feb 3, 2025
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: chore This PR contains chore tasks (cleanups, configs, tooling...) source: dependencies relates to dependencies within the repo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants