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

[Feature]: Decouple lodash import handling from build tooling #1234

Closed
mszabo-wikia opened this issue Mar 3, 2023 · 3 comments
Closed

[Feature]: Decouple lodash import handling from build tooling #1234

mszabo-wikia opened this issue Mar 3, 2023 · 3 comments

Comments

@mszabo-wikia
Copy link
Contributor

Requirement

As a Jaeger developer, I shouldn't need to rely on specific build plugins to optimize lodash imports.

Problem

Some components already import only the parts of the lodash library that they need, e.g. import map from 'lodash/map';, but some still import the entire library via e.g. import * as _ from 'lodash'; or import { debounce } from 'lodash';. The latter two stanzas only avoid importing the entire library because the current build happens to include the babel-import-plugin which optimizes these. Accidentally shipping all of lodash needlessly inflates the bundle size.

Proposal

Convert all lodash imports to lodash/subcomponent imports, or use lodash-es for ES imports that don't bring in the entire library.

Open questions

No response

@yurishkuro
Copy link
Member

As a Jaeger developer, I shouldn't need to rely on specific build plugins to optimize lodash imports.

This kinda feels like an anti-requirement to me, because it means the developer always has to worry about importing in the right way, instead of the tooling taking care of it. It's easy to forget and inadvertently bring the whole lib into the bundle again.

Is there no equivalent plugin for Vite?

Alternatively, if we could enforce importing submodules only via a linter, then it would at least provide protection agains developer mistakes.

@mszabo-wikia
Copy link
Contributor Author

I think the automatic equivalent would be lodash-es, since that's lodash built as ES modules and thus imports like import { debounce } from 'lodash-es'; will automatically do the right thing.

I'll try some more with the current vite-plugin-imp; if we fix some problematic import * as _ imports, it should be able to cover the import { debounce } from 'lodash' rewrites.

@yurishkuro
Copy link
Member

I think this is solved via #2032

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants