Coder Social home page Coder Social logo

sveltekitpwa's Introduction

Svelte-kit Progressive Web App skeleton.

Everything you need to build a Progressive Web App Svelte-kit project.

Creating a project

# Clone the project, free of git for your own project
degit [email protected]:FunMiles/SveltekitPWA.git MyApp
cd MyApp
# Install the dependencies
npm install
# or use pnpm install

Developing your code

Once you've created a project and installed dependencies with npm install (or pnpm install or yarn), start a development server:

npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open

Testing the service-worker locally

To test the service worker code and obtaining a lighthouse score, do the following operations:

# build the compiled code.
npm run build
# run the preview server.
npm run preview

Building

Before creating a production version of your app, install an adapter for your target environment. Then:

npm run build

You can still preview the built app with npm run preview, regardless of whether you installed an adapter. This should not be used to serve your app in production.

The degit code has the vercel adapter by default. If you plan to use vercel, you are set. Otherwise, replace the default with your prefered adapter.

Basic App

The git app is available as a vercel app for yours to try installing as a PWA: https://sveltekit-pwa.vercel.app/

Adjusting the list of routes

Because of the way svelte-kit serves the various routes, to be able to cold start or force-reload the PWA while offline, the service-worker needs to pre-cache all of the routes URLs. Whenever you add or remove routes, edit service-worker.js and modify the line specifying the routes to cache with your own list of routes:

// Edit the list of routes so they get cached and routed correctly, allowing
// cold start or hot reload to work offline.
const skRoutes = [ '/', '/about', '/todos' ];

Manifest, icons and description meta-data

Before publishing your own app, do not forget to modify the manifest file (static/manifest.webmanifest), overwriting the icon files (see https://github.com/onderceylan/pwa-asset-generator for an easy generator) and the meta description tag in src/routes/__layout.svelte

sveltekitpwa's People

Contributors

funmiles avatar userquin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

sveltekitpwa's Issues

Typescript & updated package errors

Error: $page.path has been replaced by $page.url.pathname
src/lib/Header/index.svelte (18, 19, 20)

Error: request.query has been replaced by request.url.searchParams
src/hooks.ts (10, 11)

Could not find a declaration file for module 'cookie'. ts(7016)
src/hooks.ts (1)

Property 'render' does not exist on type '{ request: ServerRequest<Record<string, any>, unknown>; resolve(request: ServerRequest<Record<string, any>, unknown>): MaybePromise<ServerResponse>; }'. ts(2339)
src/hooks.ts (5, 14)

Object is possibly 'null'. ts(2531)
src/hooks.ts (11)

Binding element 'url' implicitly has an 'any' type. ts(7031)
src/service-worker.ts (43)

Auditing with Lighthouse (Chrome Dev tools), throws `Failed to register...`, but works elsewhere.

Thank you for writing this straight forward ServiceWorker, I've tested many, but yours is stable and working OOTB! ๐Ÿ™‚

Issue: End-to-end testing works on desktop and mobile, offline โ€“ but auditing with Lighthouse (Chrome Dev tools), throws:

cannot register service worker DOMException: Failed to register a ServiceWorker for scope ('https://offline-phi.vercel.app/') with script ('https://offline-phi.vercel.app/service-worker.js'): Operation has been aborted

This app can not get past ~80% and takes a long time to cancel the audit in Chrome Dev tools, Lighthouse.

Do you have any suggestions? It'd be useful to be able to speed test the template before adding content.

Cannot register service worker TypeError: `Failed to register a ServiceWorker`

Hello again.

Last June/July I merged your repo into a new one, which worked across the board in Lighthouse: 100%.

So, vis-ร -vis the current problem, I've merged the repo again using SvelteKit Version 1 (npm create svelte@latest my-app), and it works, but I get: Cannot register service worker TypeError in Chrome devtools.

Here's my progress:

What to look for in devtools:

cannot register service worker TypeError: Failed to register a ServiceWorker for scope ('https://lowenergy.vercel.app/') with script ('https://lowenergy.vercel.app/service-worker.js'): ServiceWorker script evaluation failed

&

cannot register service worker TypeError: Failed to register a ServiceWorker for scope ('https://lowenergy.vercel.app/') with script ('https://lowenergy.vercel.app/service-worker.js'): ServiceWorker script evaluation failed

&

cannot register service worker DOMException: Failed to register a ServiceWorker for scope ('https://lowenergy.vercel.app/') with script ('https://lowenergy.vercel.app/service-worker.js'): Operation has been aborted

It's not clear exactly HOW to register this?

Updating Sveltekit/Vite now throws: `request in handle has been replaced with event. See https://github.com/sveltejs/kit/pull/3384 for details`

I am trying to use SveltekitPWA with the Vite/Svelte inspector, which is available using an entry to svelte.config.js:

/** @type {import('@sveltejs/kit').Config} */
const config = {
  experimental: { inspector: true },
...

However, merging SveltekitPWA with the latest Sveltekit, highlights breaking changes โ€“ notably: hooks.ts throws: sveltejs/kit#3384.

Have you had a chance to look at the new interface?

Repo: https://github.com/inspiredlabs/inspector
demo: https://offline-phi.vercel.app

How to enable debug logging?

Hi

Is there a way how to enable debug logging? As you don't have the "workbox" object available in your service worker I don't see an option how to set workbox.setConfig({ debug: true });

Thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.