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

USWDS: Remove JavaScript destructuring example from README #5928

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

aduth
Copy link
Contributor

@aduth aduth commented May 15, 2024

Summary

Improve documentation for JavaScript customization. Updated code snippets to ensure optimal build size.

Breaking change

This is not a breaking change.

Related issue

Tangentially related to #4515 . #4515 could enable optimized top-level imports using a syntax similar to the code being removed here, if combined with package.json sideEffects tree-shaking.

Related Slack discussion in USWDS public Slack: https://gsa-tts.slack.com/archives/C3F14AHSQ/p1715273540567929

Problem statement

As a developer interested in reducing the size of the JavaScript produced by USWDS, I expect that USWDS's documentation for customizing JavaScript will produce code with the intended effect of reducing of my JavaScript, so that I'm not misled into thinking my code is optimal when it's not, or confused that the JavaScript size remains the same.

Solution

The "Importing a modular component" provides two example syntaxes, but only one of them has the intended effect of reducing the size of the JavaScript bundle. The changes here remove the other example code.

Testing and review

Testing with ESBuild bundler:

echo "import USWDS from '@uswds/uswds/js';" | esbuild --bundle --minify | wc -c
   73851
echo "import accordion from '@uswds/uswds/js/usa-accordion';" | esbuild --bundle --minify | wc -c      
    5035

Before: 73.8kb
After: 5.0kb
Diff: -68.8kb (-93.2%)

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

Successfully merging this pull request may close these issues.

None yet

1 participant