All Projects → Tropix126 → sveltekit-package-template

Tropix126 / sveltekit-package-template

Licence: other
A barebones project that provides the essentials for writing highly-optimized, reusable packages in Svelte.

Programming Languages

Svelte
593 projects
SCSS
7915 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects
typescript
32286 projects

Projects that are alternatives of or similar to sveltekit-package-template

svelteify
📲 Customizable and dependencies-less Material components with Svelte
Stars: ✭ 43 (+65.38%)
Mutual labels:  sveltejs
ui-svelte
A component library for Svelte
Stars: ✭ 18 (-30.77%)
Mutual labels:  sveltejs
svelte-dev-store
This project adds the ability to use Redux Dev tools to visualise a Svelte store. It uses redux under the hood and should only be used in a development environment.
Stars: ✭ 22 (-15.38%)
Mutual labels:  sveltejs
svelte-component-library-template
A base for building Svelte component library.
Stars: ✭ 62 (+138.46%)
Mutual labels:  sveltejs
svelte-webcomponents
A ready-to-use project template to build custom elements (web components) with Svelte 3 with support and examples for web components, jest, sass, nested components with props, eslinting, stylelinting, Github actions, propagating custom events from shadow-DOM to real-DOM etc.
Stars: ✭ 22 (-15.38%)
Mutual labels:  sveltejs
Svelte Material Ui
Svelte Material UI Components
Stars: ✭ 2,081 (+7903.85%)
Mutual labels:  sveltejs
plate-app
🍛 What's on your Plate?
Stars: ✭ 49 (+88.46%)
Mutual labels:  sveltejs
svelte-box
A truffle box for svelte
Stars: ✭ 60 (+130.77%)
Mutual labels:  sveltejs
svelte-interview-questions
Concepts and Questions related to Svelte - Part of official Svelte resources list
Stars: ✭ 18 (-30.77%)
Mutual labels:  sveltejs
sapper-authentication-demo
A demonstration of Auth with Sapper + JWT + Server Side Rendering + RBAC
Stars: ✭ 102 (+292.31%)
Mutual labels:  sveltejs
svelte-persistent-store
A Svelte store that keep its value through pages and reloads
Stars: ✭ 111 (+326.92%)
Mutual labels:  sveltejs
template
Elder.js template project. It is part template, part tutorial. Dive in!
Stars: ✭ 101 (+288.46%)
Mutual labels:  sveltejs
website
Our website, built from the ground up with Svelte + Sapper to connect nonprofits, students, and everyone else in between with Bits of Good 🚀
Stars: ✭ 40 (+53.85%)
Mutual labels:  sveltejs
svelte-pagination
Example of a pagination component in Svelte
Stars: ✭ 15 (-42.31%)
Mutual labels:  sveltejs
svelte-express-boilerplate
Boilerplate for developing full stack apps with Express and Svelte.js 📦
Stars: ✭ 60 (+130.77%)
Mutual labels:  sveltejs
svelte-click-outside
A wrapper component that provides click outside detection
Stars: ✭ 28 (+7.69%)
Mutual labels:  sveltejs
svelte-progressbar
A multiseries, SVG progressbar component made with Svelte
Stars: ✭ 85 (+226.92%)
Mutual labels:  sveltejs
omnia-editor
A lightweight open source block style editor built for the modern web.
Stars: ✭ 18 (-30.77%)
Mutual labels:  sveltejs
svelte-slate
slate svelte view layer
Stars: ✭ 43 (+65.38%)
Mutual labels:  sveltejs
hacker-feud
💥 A single page web game made with Svelte.
Stars: ✭ 61 (+134.62%)
Mutual labels:  sveltejs

sveltekit-package-template

A barebones project that provides the essentials for writing highly-optimized, reusable packages in Svelte using SvelteKit's package feature.

All styles are component-scoped and preprocessed into minified and prefixed CSS during packaging using cssnano and autoprefixer. TypeScript type definitions are generated automatically from your components using svelte2tsx.

The Problem

One of Svelte's largest pitfalls currently is it's ecosystem. Compared to more mainstream frameworks, it's userland is tiny in comparison to the thousands of available components on npm. While popularity is a large contribution to this, lack of documentation and resources is also a problem.

Many packages at the moment have some sort of pitfall. Some require bundling a large stylesheet for the entire library just to use a single component. Others require developers using it to setup a package such as svelte-preprocess because they use TypeScript internally. Most of all, there really just isn't much information out there on library authoring. What many don't realize is that all of these aformentioned pitfalls can be worked around.

While svelte does offer an official component template, it lacks many features required for a production-ready package (typescript, preprocessing, styling conventions).

Getting Started

These commands will set you up with a SvelteKit development environment:

npx degit tropix126/sveltekit-package-template my-package
cd my-package
npm install # or pnpm, yarn, etc...
npm run dev

From there, you can edit the example Counter component in src/lib/Counter/Counter.svelte.

The index.ts file in src/lib exports your components for use in the package.

Packaging and Publishing

Packaging

To package your components, simply run the package command:

npm run package

This will preprocess the contents of src/lib into a package folder at the root of your project.

Publishing to NPM

After you have generated the package folder, run npm publish ./package to publish your library to NPM.

Be sure to properly configure package.json with the correct data before publishing.

Routes

Since the package command only generates it's files from src/lib, you are free to put whatever you wish in the routes folder. This could be used as a documentation site for your component, as an example.

Using your Package

Consumers of your package can import components from it in external projects like so:

<script>
    import { Component } from "my-package";
</script>

<Component />

Setting up Documentation

Most components will need documentation in some form. This template doesn't have any opinions on how documentation should be handled, however it does provide you with SvelteKit's routes folder which can be used for this. Below are some very useful svelte-focused tools that can make your life considerably easier when documenting components:

  • vite-plugin-svled is a vite port of sveld, which allows you to automatically generate API documentation for your svelte components using typescript types and JSDoc comments.
  • mdsvex is a superset of markdown that allows the usage of Svelte components and interactive logic. Since mdsvex preprocesses your markdown files into Svelte components, it can also be used as SvelteKit routes.
  • mdsvex-sveld is an mdsvex plugin that automatically outputs markdown tables for component API documentation using sveld.

Setting up Theming

If you plan to develop a large amount of components, it may become necessary to have people import a theme stylesheet containing variables. This can be done by creating a theme.css file in src/lib and having people import it from node_modules.

Developers using your library could import the theme file like so:

<script>
    import "my-package/theme.css";
    import { ComponentThatUsesTheming } from "my-package";
</script>

<ComponentThatUsesTheming />

Many modern bundlers support importing CSS as ES Modules. This is likely to be the best way of importing theme files, as they can be easily resolved from node_modules. Alternatively, you can use @import syntax with the postcss-import plugin or sass in your <style> tags, or consider CDNS such as unpkg.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].