🌟 Creating your own Custom Component Library for SvelteKit
You can create a SvelteKit component library to level up your workflow. There are possibly a few components you use over and over in new SvelteKit apps you create. You might be copy-pasting the component into each new project. If you want a maintainability boost, how about you create a SvelteKit component library? With that done all you have to do is import components into your new app like you do any external dependency. The bonus is you make changes once, in you component library and they are propagated through to all your apps via the famous
npm update command.
If that sounds like a productivity boost you'd sign up for, get your typing fingers out then hit play on the video.
📹 Create a SvelteKit Component Library: Video
🖥 The 10 Steps
Follow the video above for full, more detailed instructions.
Create a SvelteKit Component Library in 10 Steps
- Decide which components from an existing app you want to add to your component library.
- Create a skeleton SvelteKit project.
- Add the components you decided on to
- Create a
lib/index.ts. Import your components then export them as named exports.
package.json, adding this line:
- Install the
- Generate the package using
- Test locally, by creating a new skeleton project which uses the created package. Link using the relative path of the created package in the test site's
- Push your package to npm:
- Install the npm package on your test site to check it works:
- SvelteKit Packaging Docs ,
If you have found this video useful, see links below for further related content on this site. I do hope you learned one new thing from the video. Let me know if there are any ways I can improve on it. I hope you will use the code or starter in your own projects. Be sure to share your work on Twitter, giving me a mention so I can see what you did. Finally be sure to let me know ideas for other short videos you would like to see. Read on to find ways to get in touch, further below. If you have found this post useful, even though you can only afford even a tiny contribution, please consider supporting me through Buy me a Coffee.
Finally, feel free to share the post on your social media accounts for all your followers who will find it useful. As well as leaving a comment below, you can get in touch via @askRodney on Twitter and also askRodney on Telegram . Also, see further ways to get in touch with Rodney Lab. I post regularly on SvelteKit as well as Search Engine Optimisation among other topics. Also subscribe to the newsletter to keep up-to-date with our latest projects.