Skip to content

Commit

Permalink
feat: pwa
Browse files Browse the repository at this point in the history
  • Loading branch information
istudyatuni committed Nov 10, 2023
1 parent 6d85867 commit c6ff673
Show file tree
Hide file tree
Showing 5 changed files with 2,528 additions and 16 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"svelte": "^4.0.0",
"unplugin-icons": "^0.17.0",
"vite": "^4.4.11",
"vite-plugin-pwa": "^0.16.7",
"vitest": "^0.34.6"
},
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions public/icons/pwa.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions src/stores/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { get } from 'svelte/store'
/**
* Migrate `store` using `migrations` to `version`
* @param {import('svelte/store').Writable} store Store to migrate
* @param {{ [key: number]: (data: object, store: import('svelte/store').Writable) => {}}}
* migrations Migrations to apply
* @param {number} version To which version migrate
* @param {{
* [key: number]: (data: object, store: import('svelte/store').Writable) => {}
* }} migrations Migrations to apply
* @param {number} version To which version migrate
*/
export function migrateStore(store, migrations, version) {
let old = get(store)
Expand Down
43 changes: 41 additions & 2 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,51 @@ import path from 'path'

import { defineConfig, splitVendorChunkPlugin } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import { VitePWA } from 'vite-plugin-pwa'
import Icons from 'unplugin-icons/vite'

import * as postcss from './postcss.config.js'

const BASE = '/weather-site/'

/** @type {import('vite-plugin-pwa').ManifestOptions} */
const PWA_MANIFEST = {
name: 'Weather',
short_name: 'Weather',
background_color: '#26282b',
icons: [
{
src: 'icons/pwa.svg',
type: 'image/svg+xml',
sizes: '150x150',
},
],
}

const config = defineConfig({
plugins: [svelte(), Icons({ compiler: 'svelte' }), splitVendorChunkPlugin()],
plugins: [
svelte(),
Icons({ compiler: 'svelte' }),
splitVendorChunkPlugin(),
VitePWA({
registerType: 'autoUpdate',
base: BASE,
devOptions: {
enabled: true,
resolveTempFolder: () => path.resolve(__dirname, './build'),
},
manifest: PWA_MANIFEST,
manifestFilename: 'manifest.json',
workbox: {
globPatterns: [
// default
'**/*.{js,css,html}',
'**/locales/*.json',
'**/icons/weather-icons/32/*.svg',
],
},
}),
],
resolve: {
alias: {
src: path.resolve(__dirname, './src'),
Expand All @@ -26,7 +65,7 @@ const config = defineConfig({
outDir: 'build',
},
envDir: '.env',
base: '/weather-site/',
base: BASE,
optimizeDeps: {
exclude: ['tinro'],
},
Expand Down
Loading

0 comments on commit c6ff673

Please sign in to comment.