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 Request]: Babel plugin to transform imports to subpackage imports #9651

Closed
1 task done
brandones opened this issue Sep 13, 2021 · 5 comments
Closed
1 task done

Comments

@brandones
Copy link
Contributor

Summary

Asking for development of a babel plugin which would transform standard Carbon imports into subpackage imports.

Justification

This would provide the best possible DX, since developers wouldn't have to worry about identifying the right way to do a subpackage import, which presently is not obvious.

This would also solve #9540, since Typescript would work on the main namespace import.

Desired UX and success metrics

No response

Required functionality

The plugin should transform standard imports like

import { Button } from 'carbon-components-react';

into subpackage imports like

import Button from 'carbon-components-react/lib/components/Button';

or

import Button from 'carbon-components-react/es/components/Button';

Where a configuration option specifies whether to use lib or es (or any other option).

Specific timeline issues / requests

No response

Available extra resources

No response

Code of Conduct

@brandones
Copy link
Contributor Author

Oh apparently this used to exist: #3869 . My organization needs this. We're running Webpack 5 and Babel 7.

@joshblack
Copy link
Contributor

Hi there @brandones! 👋 Teams should not require needing to do sub-package imports as the project is set up for tree-shaking out of the box. Are you / your team currently experience challenges with a large bundle? If so, could you share more details about what is being included?

@brandones
Copy link
Contributor Author

brandones commented Sep 14, 2021

Oh, this is interesting. I don't know at what point we decided that carbon-components-react wasn't tree shaking, but it seems not to be true, at least any more. I just did a bundle analysis and found no difference between the normal import and subpackage import.

I do have an unrelated question, though. What's going on with "bucket," here? This is a sample project that has carbon-icons installed but doesn't actually use it:

Screenshot from 2021-09-13 16-47-16

And here's a breakdown from a real project we have, which actually does use icons:

Screenshot from 2021-09-13 17-48-15

Maybe there's something wrong with how we're bundling carbon-icons?

@joshblack
Copy link
Contributor

@brandones typically when all of the icons are included, there is a CommonJS import somewhere in the code. Here is a comment where we touched on this briefly: #6602 (comment)

Hope this helps!

@brandones
Copy link
Contributor Author

Yes, it appears that this app has an import from carbon-components-react/lib. Thanks for your help!

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