Repository: tretapey/svelte-pwa Branch: master Commit: 6958525b5ba8 Files: 11 Total size: 9.8 KB Directory structure: gitextract_gmx67wy7/ ├── .gitignore ├── README.md ├── package.json ├── public/ │ ├── global.css │ ├── index.html │ ├── manifest.json │ ├── offline.html │ └── service-worker.js ├── rollup.config.js └── src/ ├── App.svelte └── main.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ /node_modules/ /public/build/ .DS_Store ================================================ FILE: README.md ================================================ --- # Svelte PWA This is a Progressive Web App (PWA) template for [Svelte](https://svelte.dev) apps. It lives at https://github.com/tretapey/svelte-pwa. To create a new project based on this template using [degit](https://github.com/Rich-Harris/degit): ```bash npx degit tretapey/svelte-pwa my-svelte-pwa cd my-svelte-pwa ``` _Note that you will need to have [Node.js](https://nodejs.org) installed._ ## Get started Install the dependencies... ```bash cd my-svelte-pwa npm install ``` ...then start [Rollup](https://rollupjs.org): ```bash npm run dev ``` Navigate to [localhost:5000](http://localhost:5000). You should see your app running. Edit a component file in `src`, save it, and reload the page to see your changes. By default, the server will only respond to requests from localhost. To allow connections from other computers, edit the `sirv` commands in package.json to include the option `--host 0.0.0.0`. ## PWA Configuration - The `service-worker.js` and `manifest.json` files are in the `public` folder. - You should update the icons in `/public/images/icons` - For an offline experience edit the `/public/offline.html` file. - This PWA is installable. For more information on how to use check [this repo](https://github.com/pwa-builder/pwa-install). Note: If you don't want to make the app installable you can remove the script from the `index.html` file in the `public` folder. For more info, this template was made following this [tutorial](https://codelabs.developers.google.com/codelabs/your-first-pwapp) ## Building and running in production mode To create an optimised version of the app: ```bash npm run build ``` ================================================ FILE: package.json ================================================ { "name": "svelte-pwa-template", "version": "1.0.4", "scripts": { "build": "rollup -c", "dev": "rollup -c -w", "start": "sirv public", "test": "echo test" }, "devDependencies": { "@rollup/plugin-commonjs": "11.0.2", "@rollup/plugin-node-resolve": "^7.0.0", "rollup": "^1.20.0", "rollup-plugin-livereload": "^1.0.0", "rollup-plugin-svelte": "^6.1.1", "rollup-plugin-terser": "^7.0.1", "svelte": "^3.49.0" }, "dependencies": { "sirv-cli": "^0.4.4" } } ================================================ FILE: public/global.css ================================================ html, body { position: relative; width: 100%; height: 100%; } body { color: #333; margin: 0; padding: 8px; box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; } a { color: rgb(0,100,200); text-decoration: none; } a:hover { text-decoration: underline; } a:visited { color: rgb(0,80,160); } label { display: block; } input, button, select, textarea { font-family: inherit; font-size: inherit; padding: 0.4em; margin: 0 0 0.5em 0; box-sizing: border-box; border: 1px solid #ccc; border-radius: 2px; } input:disabled { color: #ccc; } input[type="range"] { height: 0; } button { color: #333; background-color: #f4f4f4; outline: none; } button:disabled { color: #999; } button:not(:disabled):active { background-color: #ddd; } button:focus { border-color: #666; } ================================================ FILE: public/index.html ================================================ Svelte PWA ================================================ FILE: public/manifest.json ================================================ { "name": "SVELTE-PWA", "short_name": "SVELTE-PWA", "icons": [ { "src": "/images/icons/icon-128x128.png", "sizes": "128x128", "type": "image/png" }, { "src": "/images/icons/icon-144x144.png", "sizes": "144x144", "type": "image/png" }, { "src": "/images/icons/icon-152x152.png", "sizes": "152x152", "type": "image/png" }, { "src": "/images/icons/icon-192x192.png", "sizes": "192x192", "type": "image/png" }, { "src": "/images/icons/icon-256x256.png", "sizes": "256x256", "type": "image/png" }, { "src": "/images/icons/icon-512x512.png", "sizes": "512x512", "type": "image/png" }, { "src": "/images/icons/maskable_icon.png", "sizes": "640x640", "type": "image/png", "purpose": "any maskable" } ], "start_url": "/index.html", "display": "standalone", "background_color": "#3E4EB8", "theme_color": "#2F3BA2" } ================================================ FILE: public/offline.html ================================================ Svelte PWA
Oops, you appear to be offline, this app requires an internet connection.
================================================ FILE: public/service-worker.js ================================================ 'use strict'; // Update cache names any time any of the cached files change. const CACHE_NAME = 'static-cache-v1'; // Add list of files to cache here. const FILES_TO_CACHE = [ '/offline.html', ]; self.addEventListener('install', (evt) => { console.log('[ServiceWorker] Install'); evt.waitUntil( caches.open(CACHE_NAME).then((cache) => { console.log('[ServiceWorker] Pre-caching offline page'); return cache.addAll(FILES_TO_CACHE); }) ); self.skipWaiting(); }); self.addEventListener('activate', (evt) => { console.log('[ServiceWorker] Activate'); // Remove previous cached data from disk. evt.waitUntil( caches.keys().then((keyList) => { return Promise.all(keyList.map((key) => { if (key !== CACHE_NAME) { console.log('[ServiceWorker] Removing old cache', key); return caches.delete(key); } })); }) ); self.clients.claim(); }); self.addEventListener('fetch', (evt) => { console.log('[ServiceWorker] Fetch', evt.request.url); // Add fetch event handler here. if (evt.request.mode !== 'navigate') { // Not a page navigation, bail. return; } evt.respondWith( fetch(evt.request) .catch(() => { return caches.open(CACHE_NAME) .then((cache) => { return cache.match('offline.html'); }); }) ); }); ================================================ FILE: rollup.config.js ================================================ import svelte from 'rollup-plugin-svelte'; import resolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import livereload from 'rollup-plugin-livereload'; import { terser } from 'rollup-plugin-terser'; const production = !process.env.ROLLUP_WATCH; export default { input: 'src/main.js', output: { sourcemap: true, format: 'iife', name: 'app', file: 'public/build/bundle.js' }, plugins: [ svelte({ // enable run-time checks when not in production dev: !production, // we'll extract any component CSS out into // a separate file - better for performance css: css => { css.write('public/build/bundle.css'); } }), // If you have external dependencies installed from // npm, you'll most likely need these plugins. In // some cases you'll need additional configuration - // consult the documentation for details: // https://github.com/rollup/plugins/tree/master/packages/commonjs resolve({ browser: true, dedupe: ['svelte'] }), commonjs(), // In dev mode, call `npm run start` once // the bundle has been generated !production && serve(), // Watch the `public` directory and refresh the // browser on changes when not in production !production && livereload('public'), // If we're building for production (npm run build // instead of npm run dev), minify production && terser() ], watch: { clearScreen: false } }; function serve() { let started = false; return { writeBundle() { if (!started) { started = true; require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], { stdio: ['ignore', 'inherit', 'inherit'], shell: true }); } } }; } ================================================ FILE: src/App.svelte ================================================

Hello {name}!

This is a starter template for a Svelte PWA, based in the Svelte template

You will find the manifest.json file and the service-worker.js file in the public folder

To update the proper icons for the PWA check /public/images/icons

================================================ FILE: src/main.js ================================================ import App from './App.svelte'; const app = new App({ target: document.body, props: { name: 'world' } }); export default app;