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

[feat] Allow developers to import individual components without tree shaking #2660

Open
Brenden-Smith opened this issue Nov 13, 2023 · 1 comment
Labels
type: feature New feature or request

Comments

@Brenden-Smith
Copy link

Does your feature request relate to a specific USWDS component?

No

What USWDS Version is this feature present in?

Not applicable

Is your feature request related to a problem? Please describe.

When you import one component from the library through tree shaking, it seems to import the entire library under the hood. Currently, the individual components don't seem to be exposed to the developer, and tree shaking is the only method of import. This is a problem when working with frameworks where bundle size is of importance, such as Next JS. See below examples:

page1

// page1

import { Button } from "@trussworks/react-uswds";
...

page2

// page2

import {
  Button,
  Banner,
  TextInput,
  Form,
  DatePicker,
  Modal,
  Icon,
} from "@trussworks/react-uswds";
...

Build output
Screenshot 2023-11-13 at 12 48 28 PM

As you can see, the bundle sizes for page1 and page2 are the same. This implies that importing one component imports the whole library. While this example was with a fresh app with nothing else in it, on a full project, that amount makes a big difference.

Describe the solution you'd like

Expose the ability to import one component from a specific file. Such as:

// Current
import { Button, TextInput } from "@trussworks/react-uswds";

// Single file
import Button from "@trussworks/react-uswds/components/Button";
import TextInput from "@trussworks/react-uswds/components/TextInput";

This would reduce the bundle size by only importing the components and code necessary.

Describe alternatives you've considered

The only other alternative is to manually implement USWDS components in my project and allow imports this way, but that would be counter to the idea of this library.

Additional context

If this is already possible, and I just missed it, let me know. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants