I've build widget/component that I want to bundle and use in other projects.
Unanswered
Rhinelander posted this in #help-forum
RhinelanderOP
I made some component that uses shadcn, own css and bunch of other components. I want to use that component in other projects by bundling it and hosting it so i can just add few lines of js do add that component. Component also use it's own api route but that could be moved if there is no way to bundle it like that.
Does anyone have idea how to do that?
Does anyone have idea how to do that?
41 Replies
I mean you could just make your own nom package? Is that what you mean?
If you want something private that changes things slightly
RhinelanderOP
Okay, I'll explain everything. I am building a chatbot widget. A button, positioned at the corner of the screen, triggers a modal. This is part of my SaaS product. When a user signs up and accesses their dashboard, they can control settings like color, access, etc. The user then adds a script tag with the location where I will host the package, and includes their secret key, which enables them to use the chatbot. This ensures that only authorized users have access. I also want the widget to be compatible with platforms like Shopify, WordPress, or custom non-JavaScript environments. Does that make more sense?
RhinelanderOP
Not really sure how to do it 🙂
RhinelanderOP
but should I do this kind of thing by packaging it with npm?
but
if u want to make it available for people with no knowledge i would suggest bundling a small codebase
RhinelanderOP
how do i do that
RhinelanderOP
I used webpack yesterday but it failed but i was tired and probably didn't set it up correctly. I am doing this rn
keep the bundle size as low as possible
and try to keep everything on the serverside
RhinelanderOP
well it is chatbot so some of the stuff can not be done serverside
yes ofc
im talking about the payload itself
u can ssr render parts of ur widget
yes thats it as u cant just change the origin and bypass cors
so its easy to verify the requested domain on the serverside
u dont need a private key on the clientside
hope that helped
RhinelanderOP
i finally bundled it successfully
now i am going to try if it works as expected
also
its 2.47 MiB
in size
seems like a lot
not zipped yet
RhinelanderOP
well it doesn't seem to be working. it bundled successfully but when i create index.html file in root it just shows the icon no interactivity. Icon is not even positioned correctly
should i rebuild this component in plain react?
no other libraries