Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 27, 2021 09:33 pm GMT

Create a PWA with Sveltekit | Svelte

I've been using sveltekit and svelte for over a year now. I'm also anxiously waiting for it to be matured enought to beat NextJs in terms of community. But I like them both.

So, on this weekend I wanted to turn one of my projects into a PWA. When I wanted to do with NextJs projects there were a lot of tutorials. But I couldn't find many guides for svelte beginners.

That's because svelte has pwa functionality built into it.

Note !

Basic things for all PWAs

  • A website
  • manifest.json [ basic icons,names,shortcuts]
  • service-worker [ for offline cache ]

So let's get on with it.

lets-go.gif

First:

We'll create a demo Sveltekit project:

npm init svelte@next my-app

create.png

Then we'll choose a simple config in vite for the sake of this article:

config.png

Choose typescript because ts >>>> js:

svelte-kit-config.png

Now we have a demo project setup with typescript, it will be straight-forward from here on:

note.png

Let's get into our directory:

cd my-app

And run:

yarn

yarn-output.png

After that,

  • In the /static directory, We'll create a manifest.json.
  • When svelte compiles the whole application the static files will be copied over to the build folder.

manifest.json

Then we'll refer our manifest.json in src/app.html.

app.html

And finally we'll create our src/service-worker.ts

Svelte will automatically detect the service-worker in the src folder's root and then register our service worker during build.
Isn't that neat?

service-worker.ts

Now we just need to build or app using yarn build:
build.png

Now we can preview our build using yarn preview:

preview.png

'0' is that a 'install app' button,

output-button.png

Svelte makes it easy to make PWAs.

The source code of this project lies at:

https://github.com/100lvlmaster/svelte-pwa

You can find me at:

https://100lvlmaster.in


Original Link: https://dev.to/100lvlmaster/create-a-pwa-with-sveltekit-svelte-a36

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To