Svelte vs Svelte Kit - What's The Difference?

Syntax
15 Oct 202110:26

Summary

TLDRIn this informative video, Scott from Level Up Tutorials clarifies the distinction between Svelte and SvelteKit. Svelte is likened to front-end frameworks such as React or Vue.js, focusing on the manipulation of the DOM through JavaScript. In contrast, SvelteKit is a comprehensive toolkit for building applications and websites with Svelte, offering features like file-based routing, server-side rendering, and API support. The video also touches on SvelteKit's unique components, such as adapters, loading functions, and layouts, emphasizing how they facilitate the development process. Scott encourages viewers interested in learning Svelte and SvelteKit to visit Level Up Tutorials for in-depth courses and resources.

Takeaways

  • 📝 Svelte is a front-end framework analogous to React or Vue.js, focusing on writing code that manipulates the DOM through features like two-way binding and single-file components.
  • 🛠️ SvelteKit is a toolset for building applications, static sites, and packages with Svelte, providing a structured way to develop projects using the Svelte framework.
  • 🎯 The primary difference between Svelte and SvelteKit is that Svelte is the core framework for front-end development, while SvelteKit encompasses the tools and features needed to build complete applications.
  • 🔄 SvelteKit includes innovative features like an adapter system for determining the output of the site, whether it's static generation like Gatsby or server-side rendering for Node.js applications.
  • 🗺️ Routing in SvelteKit is based on the folder structure of the application, making it intuitive and similar to other modern web development frameworks.
  • 🚀 SvelteKit's loading functions allow for server-side data fetching and preparation before the client-side render, enhancing performance and user experience.
  • 🔄 Layouts in SvelteKit are special files that wrap around router files within the same folder, providing a way to create consistent structures across the application.
  • 📌 Hooks in SvelteKit are not React hooks but are more akin to traditional web development hooks, allowing for interaction with the application's rendering cycle.
  • 📋 SvelteKit comes with additional modules for development, such as app navigation, paths, stores, and aliasing, making it easier to build and manage applications.
  • 🌐 SvelteKit supports various output modes, including Node.js apps, static generation, client-only, and server-only deployments, offering flexibility for different types of projects.
  • 🎢 The SvelteKit community offers a wealth of learning resources, including Level Up Tutorials, which provide comprehensive courses on Svelte and SvelteKit for those looking to develop their skills.

Q & A

  • What is Svelte and how does it relate to Svelte Kit?

    -Svelte is a front-end framework similar to React or Vue.js, which allows developers to write code that produces JavaScript to manipulate the DOM. Svelte Kit, on the other hand, is a set of tools for building applications, static sites, and packages with Svelte. Essentially, Svelte is the core framework, while Svelte Kit is the ecosystem for creating full-fledged web applications.

  • What are the key differences between Svelte and Svelte Kit?

    -Svelte is focused on the front-end and is used for creating the interactive parts of web applications. It deals with features like two-way data binding, single-file components, and reactive updates. Svelte Kit, however, includes additional features like an adapter for outputting the site, a file-based routing system, server-side loading of data, and support for various deployment targets like static sites or server-side rendered applications.

  • What is the role of an adapter in Svelte Kit?

    -An adapter in Svelte Kit determines how the application will be run or outputted. It can be used to create a statically generated site, a Node.js application, or even a Cloudflare worker. The adapter allows developers to choose the output format of the site, whether it's server-side rendered, client-side only, or a combination of both.

  • How does routing work in Svelte Kit?

    -Svelte Kit uses a file and folder-based routing system. The structure of the application's directories dictates the routes of the site. This means that the file system layout directly corresponds to the URLs and the pages that are accessible to users.

  • What is the concept of 'loading' in Svelte Kit?

    -In Svelte Kit, 'loading' refers to the process of fetching and preparing data on the server-side before the client-side rendering takes place. This can be used to improve performance by loading data quickly from the server. Additionally, the loading function can handle tasks like redirects, allowing for more dynamic control over navigation within the application.

  • Can you explain the concept of 'layouts' in Svelte Kit?

    -Layouts in Svelte Kit are special files that wrap around other components, particularly the ones generated by the file-based router. They are denoted by having two underscores in their file names. A layout requires a 'slot' which is where the content from the router files is inserted. This concept is similar to how slots work in Svelte components and allows for a consistent structure across different pages of the application.

  • What additional modules does Svelte Kit provide for development?

    -Svelte Kit comes with several additional modules to aid in development. These include 'app/env' for accessing environment information, 'app/navigation' for programmatic interaction with the router, 'app/paths' for base path information, and 'app/stores' for default reactive stores. These modules help developers manage various aspects of the application's behavior and interaction with the user.

  • How does Svelte Kit handle prefetching of routes?

    -Svelte Kit offers a feature called 'svelteKit prefetch' that allows for prefetching of routes. This means that the application can load parts of the site in the background, improving the overall user experience by having content ready to display as soon as the user navigates to it.

  • What is the command-line interface provided by Svelte Kit?

    -Svelte Kit includes a command-line interface that allows developers to easily run various modes and tasks. Commands like 'dev' for development mode, 'build' for creating a production build, and 'preview' for previewing the production build are available. This simplifies the development and deployment process for Svelte Kit applications.

  • How does Svelte Kit handle different deployment targets?

    -Svelte Kit is flexible when it comes to deployment. It supports various deployment targets such as static sites, Node.js applications, client-only applications, and even server-only applications. This is achieved through the use of different adapters, which dictate the output and behavior of the application depending on the chosen deployment method.

  • What is the relationship between Svelte Kit and other Svelte-based platforms like Elder.js or Astro.build?

    -Svelte Kit is a specific ecosystem for building applications with Svelte, while other platforms like Elder.js or Astro.build are alternative ways to consume and build with Svelte. While Svelte can be used across these different platforms, Svelte Kit is specifically designed to provide a comprehensive set of tools for application development, including features like routing, data loading, and deployment options that may not be present in other Svelte-based platforms.

Outlines

00:00

🚀 Introduction to Svelte and SvelteKit

This paragraph introduces the speaker, Scott from LevelUp Tutorials, and sets the stage for a discussion on Svelte and SvelteKit. Scott addresses the common confusion between the two, noting that while Svelte is frequently mentioned online, SvelteKit is less well understood by newcomers. He promises a brief explanation rather than an in-depth tutorial, aiming to clarify when and how to use Svelte and SvelteKit together in web development.

05:02

📚 Understanding the Differences: Svelte vs SvelteKit

Scott explains the fundamental difference between Svelte and SvelteKit using analogies to other popular frameworks. Svelte is likened to React or Vue.js, serving as a front-end framework for writing code that manipulates the DOM. SvelteKit, on the other hand, is a toolset for building applications, static sites, and packages with Svelte. It includes features like adapters for outputting the site, a file-based routing system, and a unique loading function for server-side data fetching and redirects. The explanation positions SvelteKit as the go-to for building apps with Svelte, while emphasizing that Svelte itself is the front-end framework utilized within SvelteKit.

10:03

🛠️ Additional Features and Capabilities of SvelteKit

This paragraph delves into the additional features that make SvelteKit stand out for building web applications. It covers the concept of layouts, which are special files that wrap around the router files, and hooks, which are reminiscent of web development hooks rather than React hooks. Scott also mentions various modules included with SvelteKit, such as app navigation, paths, stores, and aliasing. He touches on SvelteKit's flexibility in outputting code for different types of applications and its command-line interface. Furthermore, he highlights SvelteKit's compatibility with Svelte's configuration options and Rollup plugins, wrapping up with a note on the potential for future exploration of SvelteKit's features.

🎓 Learning Resources and Course Promotion

In the final paragraph, Scott promotes LevelUp Tutorials as a resource for learning Svelte, SvelteKit, and other related technologies. He mentions the regular release of new tutorial courses and the variety of content creators contributing to the platform. Scott specifically points out the current month's focus on Astro.build and Svelte's role in it. He encourages viewers to visit LevelUp Tutorials for a comprehensive learning experience and mentions a discount for annual subscriptions, emphasizing the value of the content provided.

Mindmap

Keywords

💡Svelte

Svelte is a front-end framework analogous to React or Vue.js, allowing developers to write code that produces JavaScript for manipulating the DOM. It is the fundamental technology used within SvelteKit for rendering user interfaces. In the script, Svelte is described as the core framework for building interactive web applications.

💡SvelteKit

SvelteKit is a set of tools and conventions for building web applications with Svelte. It includes features like routing, server-side rendering, and API support, making it a comprehensive solution for developing web applications. Unlike Svelte alone, SvelteKit provides a complete ecosystem for creating full-stack applications.

💡Adapter

An adapter in SvelteKit determines how the application is outputted. It can be used for statically generating sites like Gatsby does, or for creating server-based applications, or even running in cloud environments like Cloudflare Workers. Adapters provide flexibility in how the application is deployed and accessed.

💡Routing

Routing in SvelteKit refers to the system that manages the navigation between different pages or views within an application. It uses a file-based approach, where the folder structure of the application determines the URLs and the corresponding components or pages that load. This makes it easy to manage and scale the navigation of a web application.

💡Loading

Loading in the context of SvelteKit is a concept that allows developers to define how and when data is loaded, particularly on the server-side before the client-side rendering takes place. This can improve performance by fetching and preparing data ahead of time, and it can also handle tasks like redirects.

💡Layouts

Layouts in SvelteKit are special files that wrap around other components to provide a consistent structure or design across different pages. They are similar to the concept of slots in Svelte, and they require a slot to be defined. Layouts help in maintaining a uniform look and feel across an application by encapsulating common elements like headers, footers, or navigation menus.

💡Hooks

While not directly mentioned in the script, hooks in web development generally refer to functions that allow developers to 'hook into' different parts of an application's lifecycle, such as rendering or state management. In the context of SvelteKit, hooks might be similar to other web development patterns but are distinct from React hooks.

💡Additional Modules

SvelteKit comes with additional modules that assist in the development process. These modules provide functionalities like environment information, navigation, and prefetching of routes. They are designed to enhance the development experience and streamline common tasks within a SvelteKit application.

💡Prefetching

Prefetching in SvelteKit is a technique used to improve the performance of web applications by loading resources (like pages or data) in advance, based on user behavior predictions. This technique helps reduce the perceived load time by having content ready before the user actually requests it.

💡Configuration Options

Configuration options in SvelteKit allow developers to customize the behavior and settings of their applications. These options can include how the application is built, its development environment, and how it interacts with other tools or services.

💡Command Line Interface (CLI)

The Command Line Interface, or CLI, is a tool provided by SvelteKit that allows developers to interact with their applications through the command line. It enables actions like running the application in development mode, building the application for production, and previewing the built application.

Highlights

Svelte and SvelteKit are often confused but they serve different purposes in web development.

Svelte is a front-end framework similar to React or Vue.js, focusing on the manipulation of the DOM through JavaScript.

SvelteKit is a toolset for building applications, static sites, and packages with Svelte, offering a more comprehensive development experience.

SvelteKit includes features like an adapter for outputting the site, routing, loading, and layouts, which are not present in Svelte alone.

The adapter in SvelteKit allows developers to choose the output method of their site, such as static generation or server-side rendering.

SvelteKit uses a file and folder-based routing system, simplifying the process of defining site routes based on the application's structure.

Loading in SvelteKit is a concept for server-side data fetching and preparation before the client-side rendering takes place.

Layouts in SvelteKit are special files that wrap around router files, providing a way to create consistent structures across the site.

SvelteKit includes additional modules like app navigation, paths, stores, and aliasing to enhance the development process.

SvelteKit supports various output methods, including Node apps, static generation, client-only, and server-only deployments.

SvelteKit has a command-line interface for easy management of development modes, building, and previewing.

SvelteKit is built on top of Vite, offering all the Vite configuration options and the ability to use Rollup plugins.

Svelte can be used with other platforms like Elder.js or Astro.build, but SvelteKit is the recommended toolset for building applications with Svelte.

Level Up Tutorials offers courses on Svelte and SvelteKit, including animation and component development.

The upcoming course on Astro.build will feature the use of Svelte within the Astro framework.

By understanding the differences between Svelte and SvelteKit, developers can make informed decisions on the right tools for their web development projects.

Transcripts

play00:00

hey what's up this is scott with level

play00:02

up tutorials and in this weekly's felt

play00:05

we're going to be talking about svelt

play00:06

and svelt kit now this is a question i

play00:09

see pop up on reddit twitter everywhere

play00:11

all the time what's the difference

play00:12

between svelt and svelt kit uh whether

play00:15

or not there's confusion there or people

play00:17

just are new to the platform and see

play00:18

people building things with self kit and

play00:21

or don't know what the difference is

play00:22

this will be a quick explainer it's not

play00:24

going to be anything crazy in depth it's

play00:26

by all means not going to be like a

play00:28

full-on tutorial on using either of

play00:30

these projects but it will hopefully

play00:32

give you an idea of when to use what and

play00:35

where and how to talk about these things

play00:37

as if they're these separate things but

play00:40

uh used together and how they are so

play00:43

okay let's talk about the difference

play00:44

between svelt and sveltkit

play00:47

svelt is more analogous if we're looking

play00:50

at front-end frameworks it's more

play00:51

analogous to something like react or

play00:54

even vue.js right it's the framework

play00:56

it's the front-end framework it's the

play00:58

thing that allows you to write the code

play01:00

and it spits out

play01:02

the

play01:02

javascript that manipulates the dom okay

play01:06

that's felt when you use the the two-way

play01:09

binding when you use what other kind of

play01:12

features the um the single file

play01:14

components the svelt files those are all

play01:16

svelte things what about sveltkit

play01:19

well sveltkit is how you build apps

play01:22

sites static apps static sites packages

play01:25

that's how you build things with svelt

play01:28

and in the past

play01:30

you've built

play01:31

uh things with svelten in many other

play01:33

ways whether you're using svelt's own

play01:35

thing that used to be called it was

play01:36

sapper was the the precursor just felt

play01:38

kit or maybe use something like elder js

play01:42

there's a number of these different

play01:43

svelte projects but sveltkit is

play01:46

essentially the way to build apps or

play01:49

websites with svelt okay so svelte is

play01:52

the front-end framework and svelte kit

play01:54

is essentially the kit to build

play01:56

applications with now sveltkit has a lot

play01:59

of really neat features that make it

play02:01

stand out and be different from some of

play02:03

these other platforms so if we're going

play02:05

to try to keep up with this analogous

play02:07

thing if you're coming up from the react

play02:09

world svelt is to react as spelt kit is

play02:13

to next js or perhaps even gatsby and if

play02:17

you're coming from the view land of

play02:19

things uh svelte is to view as felt kit

play02:22

is to nuxt js and if you're not coming

play02:24

from either of these think about it like

play02:26

this svelte is the front-end framework

play02:28

sveltekit is what you use to build apps

play02:30

with svelte okay that is at the very

play02:33

most plain english the best way to

play02:34

possibly describe it so if you were

play02:36

saying i want to i want to build an

play02:38

application from scratch and this thing

play02:39

needs to be server side rendered and

play02:42

needs to have an api you'd pick up svelt

play02:44

kit you wouldn't even you wouldn't pick

play02:46

up svelte itself you'd pick up sveltekit

play02:49

to build that application now spelled

play02:51

kid uses svelt so you are writing the

play02:55

app in spelt

play02:56

but sveltkit again is the tools in the

play02:59

kit for you to build these applications

play03:01

now what does it include that makes it

play03:03

do these things well it includes things

play03:05

like an adapter now an adapter is how

play03:08

you output the site

play03:10

so let's say you wanted to have a

play03:12

statically generated site like a gatsby

play03:14

site it's a site that takes your

play03:16

javascript and outputs it in just

play03:18

straight up html that is going to be

play03:20

using an adapter in swelt kit or if you

play03:23

want to say i want this actually be a

play03:24

node app where everything is generated

play03:26

on the server that's also an adapter or

play03:29

maybe you want this to run in a

play03:30

cloudflare worker that's an adapter okay

play03:32

so an adapter is something that chooses

play03:34

the output of the site and it's really

play03:36

neat that you get to pick that so you

play03:37

don't have to have your different

play03:39

project built on something else just to

play03:40

have a static output right now what else

play03:44

is included in spell kit also in spell

play03:47

kit is the routing system now just like

play03:50

next js or some of these other ones it

play03:52

uses a file

play03:54

uh folder based routing system as in uh

play03:58

based on the folder structure of your

play04:00

application it determines the routes of

play04:03

your site now routers uh as a concept is

play04:07

basically when you hit a url when you go

play04:09

to a url in your browser where does the

play04:11

app go like what files does this thing

play04:14

load what components does this render

play04:17

so

play04:19

spell kit includes routing

play04:21

okay it includes adapters how the

play04:24

application will eventually be run

play04:26

but it also includes something called

play04:27

loading now loading is an interesting

play04:30

concept and loading is basically where

play04:33

you define the data can be loaded uh in

play04:36

the server side before the client side

play04:39

render takes place

play04:40

again this can also be run just straight

play04:42

up client side if you want it to be that

play04:44

way or it can be run both so a loading

play04:47

function is basically this is where you

play04:50

fetch all your data before the component

play04:52

gets to be run okay

play04:54

so this loading function is something

play04:57

that is only in spell kit is not in

play04:59

svelt and this thing runs essentially

play05:01

before the component even starts to

play05:03

mount so unmount none of that stuff will

play05:06

be called until long after the well

play05:09

maybe not long after but after the load

play05:11

function has been run and load functions

play05:13

can do a number of things it can like i

play05:14

said fetch your data prepare that data

play05:16

for server-side rendering but it also

play05:18

can handle redirects let's say you want

play05:19

to uh look at something on the server

play05:22

you know based on that maybe perhaps do

play05:24

a redirect so okay we have page routing

play05:28

we have the output we have

play05:30

um the loading

play05:32

we also have layouts now layouts is a

play05:35

concept that kind of exists in felt as

play05:37

in we have this this concept is felt

play05:39

called slots which is how you insert

play05:41

something into another component in

play05:43

react it's children but in svelte you

play05:45

have the idea of a slot now a layout in

play05:48

sveltkit is a special file that has two

play05:50

underscores in front of it and it

play05:52

requires a slot and it will essentially

play05:54

wrap around the file based router files

play05:57

within that same folder okay it's just

play05:59

what you would expect when you hear the

play06:01

word layout if you've worked in any of

play06:02

these platforms now in addition to that

play06:04

there's some other little things like

play06:06

hooks which aren't necessarily anything

play06:08

you need to think about too much if

play06:10

we're giving a 101 here these aren't

play06:12

like essential it's not analogous to

play06:14

react hooks no relation there whatsoever

play06:16

this is more like what you're used to

play06:18

with any sort of web development hook

play06:20

you know when react started calling them

play06:22

hooks it was kind of weird that they did

play06:23

because hooks has this other connotation

play06:25

where it's like you can hook into parts

play06:27

of the application uh the rendering

play06:29

cycle right and that that's kind of what

play06:31

hooks are and react in a way but it's

play06:34

confusing right so also svelka has a

play06:36

number of additional modules which are

play06:38

basically packages that come with felt

play06:40

kit to help you in your development flow

play06:41

things like app env which gives you

play06:43

environment information whether or not

play06:45

your application's running in

play06:46

development mode those types of things

play06:48

we also have things like app navigation

play06:49

which allows you to interact with the

play06:51

router there's a go to function to go to

play06:53

a url invalidate

play06:56

prefetch prefetch routes a lot of cool

play06:58

stuff in here

play06:59

but just basically you could think of

play07:01

this as the router right if you want to

play07:03

have access to the router programically

play07:04

that's how you do it um there's app

play07:07

paths which are some base path

play07:08

information app stores which are some

play07:10

default stores um some reactive stores

play07:13

that come baked into sphelp kit such as

play07:16

whether or not the page is currently

play07:18

navigating we use this on level up

play07:19

tutorials that if the page is currently

play07:21

navigating show a loading spinner some

play07:23

people use this for some different

play07:24

things but that's what exists

play07:26

we have things like the page again i'm

play07:28

not going to do a total in depth about

play07:30

everything here

play07:31

there's also some aliasing going on here

play07:33

there's some neat stuff but basically at

play07:35

the end of the day this is the stuff

play07:36

that allows you to again uh this is the

play07:39

stuff that allows you to build websites

play07:40

and applications um with svelte

play07:44

now some neat stuff okay uh svelkit has

play07:47

some really neat stuff that i would love

play07:49

to dive more into in this video but like

play07:51

stuff like uh svelkit prefetch to

play07:53

prefetch routes again this is all

play07:54

routing related spell kit no scroll

play07:58

what else do we have here some amp mode

play08:00

i don't use amp myself so um i don't as

play08:04

i honestly don't know too much about amp

play08:06

as it exists in spell kit because i just

play08:08

don't straight up use it it allows you

play08:10

again to choose how you're outputting

play08:12

your code whether it is as a node app

play08:13

and ssr whether it's statically

play08:15

generated whether it's client only or

play08:17

even just server only right you can do

play08:18

all of that now there's also a command

play08:20

line interface that allows you to just

play08:22

basically run dev mode build preview

play08:24

package and sveltkit is built on top of

play08:27

veet so uh you you end up having all the

play08:29

veeat configuration options as well

play08:31

which

play08:32

is awesome and again v uses rollup

play08:35

plugins so you can use rollup plugins in

play08:37

spell kit it all works very very well

play08:40

very super good um and and that's it i

play08:42

mean there's some configuration options

play08:44

but if we're doing like what's the

play08:45

difference here i think i've made it

play08:47

pretty clear what the difference is um

play08:48

there's some neat stuff about um

play08:51

just in general what's going on here but

play08:53

again at the end of the day you're

play08:55

building applications with spell kit and

play08:58

you're most likely not building

play08:59

applications with svelt but you're using

play09:01

svelte in sveltkit to build applications

play09:04

okay

play09:06

so like think about it this way there's

play09:07

other platforms that can consume svelte

play09:10

uh whether that is elder js or astro dot

play09:13

build right astro build you can use felt

play09:15

and astronaut dot built but you're not

play09:16

using spelled kit in astro build if that

play09:19

makes sense right so i hope this is a

play09:21

quick explainer again i'm hoping not to

play09:24

go too too in-depth here i don't want to

play09:26

um you know turn this into a full-on

play09:28

every every little thing that is about

play09:30

here but what i do want to do is make it

play09:31

very clear in plain english what the

play09:33

difference is here because i do hear

play09:35

this question come up all the time i'm

play09:36

hearing the words felt i'm hearing the

play09:38

words spell kit i don't know the

play09:40

difference

play09:41

that's the difference thank you so much

play09:42

for watching and if you'd like to learn

play09:44

svelte and spelt kit or svelte in spell

play09:46

kit or

play09:47

s felt with sappers still leaving for

play09:50

some reason but i would recommend going

play09:51

to spell kit um if you want to learn

play09:53

spelt spell kit animating spelled

play09:55

buildings fall components any of that

play09:57

head on over to level up tutorials dot

play10:00

com uh if you sign up for the year you

play10:02

can save 25

play10:04

um and that's a really good deal because

play10:06

we come out with a new tutorial course

play10:07

every single month and we have some

play10:09

brand new courses coming from some

play10:10

extremely talented content creators as

play10:13

well as a ton of new courses from yours

play10:15

truly doing all sorts of really cool

play10:16

stuff in fact this month's course is on

play10:18

astro astro.build and we're going to be

play10:21

using some svelt in astro you better

play10:23

believe so thanks so much for watching

play10:24

and i will see you in the next one

Rate This

5.0 / 5 (0 votes)

Related Tags
SvelteDifferencesSvelteKitTutorialsWebDevelopmentFrontendFrameworksReactAnalogiesNextJSComparisonVueJSLikeServerSideRenderingStaticSiteGeneration