Decrease the bundle size #1962
Replies: 9 comments
-
I would love to see the separation of authentication logic (clerk.load(), clerk.user...) from the UI parts (clerk.mountSignIn()...). Bundle size seems to be mostly impacted by the UI parts and could only be imported when needed, e.g. a login page. |
Beta Was this translation helpful? Give feedback.
-
Hello @fmoessle @hornta , could u give the following snippet a try ? import Clerk from "@clerk/clerk-js"; import Clerk like this import Clerk from "@clerk/clerk-js/headless"; This should bring the bundle size down significantly. |
Beta Was this translation helpful? Give feedback.
-
On another note @hornta , do you mind sharing why you have chose to import Clerk like that in an React application ? |
Beta Was this translation helpful? Give feedback.
-
@panteliselef That decreases the size, although it's still the largest dependency which is weird because it's "just authentication" compared to for example the react footprint :-) But I'm OK with it being like this for now. For some reason vscode couln't find out that the package exported that and there seems to be no typings for this headless as well, but it works at runtime and it can build it.
I need to use Clerk outside of the "react world", for example in redux toolkit querys |
Beta Was this translation helpful? Give feedback.
-
I mean for what Clerk do, it being larger than or equally large as react feels like it has unoptimized code and/or imports things bundlers can't treeshake away. It's mostly communication with Clerk backend. |
Beta Was this translation helpful? Give feedback.
-
I also experience missing types. As a workaround, you can import the type like this import type ClerkType from '@clerk/clerk-js' and tell typescript to handle the headless clerk instance to be of the type const clerk: ClerkType = new Clerk('...') |
Beta Was this translation helpful? Give feedback.
-
@panteliselef If using I ended up having two instances of clerk in my app: 1 global instance ( |
Beta Was this translation helpful? Give feedback.
-
@fmoessle I believe the following would work for you import Clerk from "@clerk/clerk-js/headless";
const clerkJSinstance = new Clerk(
import.meta.env.VITE_APP_CLERK_PUBLISHABLE_KEY,
);
<ClerkProvider Clerk={clerkJSinstance}>
{...}
</ClerkProvider> |
Beta Was this translation helpful? Give feedback.
-
Hello! We're tracking our feature requests now in feedback.clerk.com. If your suggestion is already in the list of proposed changes, please upvote. Otherwise, please create an entry. Thanks! Our feedback platform will be the source of truth for feature requests going forward and your input and votes will help us shape the roadmap. Thanks for using Clerk! 💙 |
Beta Was this translation helpful? Give feedback.
-
Preliminary Checks
I have reviewed https://clerk.com/docs for existing features that would solve my problem
I have searched for existing feature requests: https://github.com/clerkinc/javascript/issues
This issue is not a question, general help request, or anything other than a feature request directly related to Clerk. Please ask questions in our Discord community: https://clerk.com/discord.
Description
Clerk is almost 50% of my bundle size. It's built with Vite and I only use it like this:
It would be nice to have the react clerk package export Clerk so that I can initialize the client outside of React, then I wouldn't need to install the
@clerk/clerk-js
package.This report is generated using this rollup plugin https://www.npmjs.com/package/rollup-plugin-analyzer
Affected Packages
@clerk/clerk-js
Beta Was this translation helpful? Give feedback.
All reactions