Reduce bundle size for @azure/identity with better tree shaking support #36942
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Packages impacted by this PR
Issues associated with this PR
None
Describe the problem that is addressed by this PR
This PR reduces the bundle size of this library by making it more tree shakable. Before this PR the following code would pull in 851KB of unminified js from @azure/identity. This PR brings that down to 753KB. Other authentication flows should see similar results.
Two fixes that are addressed in this PR are.
import *(851kb to 790kb)Below are screenshots of a before and after bundle for only ClientCertificateCredential.
Future improvements
Taking a look at the resulting bundles I can still see some easy wins to reduce the bundle size further. One that immediately stands out to me, is that jsonwebtoken pulls in quite some js. E.g. jsonwebtoken pulls in semver which accounts for almost 10% of the whole bundle size (61.3KB) and some more. Sadly this needs to be fixed upstream in the msal libraries which are not in this monorepo.
What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen?
The msalClient could have been trimmed down to only having a context and the auth flow specific code could have been moved to it's respective flows. Since many of the functions here follow a similar pattern they can easily get out of sync and get harder to maintain. I suspect that that's why they were structured like this in the first place, and that's why I kept it like this.
Are there test cases added in this PR? (If not, why?)
No, tests only had to get plumbed up correctly again. No new logic was added.
Provide a list of related PRs (if any)
None
Command used to generate this PR:**(Applicable only to SDK release request PRs)
None
Checklists