Skip to content

Commit 370f1d0

Browse files
authored
feat!: refactor plugin to allow work with latest kit changes (#32)
* fix: refactor plugin to allow work with latest kit changes * chore: udpate pnpm version * chore: fast-glob order * chore: allow kit build custom ts sw * chore: remove kit types from sw * chore: use define to configure `process.env.NODE_ENV` * fix: `process.env.NODE_ENV`on vite config example * chore: cleanup + log on manifest transform * fix: console.log lint * chore: simplify configuration to switch between strategies * chore: include webmanifest in globPatterns * chore: handle self destroying sw properly * chore: fix min kit peer version to 1.3.1 * chore: remove `latestKit` option * chore: include min kit version on readme
1 parent 57a3499 commit 370f1d0

File tree

15 files changed

+729
-728
lines changed

15 files changed

+729
-728
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Zero-config PWA Plugin for SvelteKit
4444

4545
## 📦 Install
4646

47+
> From v0.2.0, `@vite-pwa/sveltekit` requires **SvelteKit 1.3.1 or above**.
48+
4749
```bash
4850
npm i @vite-pwa/sveltekit -D
4951

build.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export default defineBuildConfig({
77
clean: true,
88
declaration: true,
99
externals: [
10+
'fast-glob',
11+
'kolorist',
1012
'vite',
1113
'vite-plugin-pwa',
1214
'workbox-build',

examples/sveltekit-ts/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shell-emulator=true

examples/sveltekit-ts/package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,28 @@
55
"sw-dev": "vite dev",
66
"dev": "vite dev",
77
"build": "vite build",
8+
"build-self-destroying": "SELF_DESTROYING_SW=true vite build",
89
"preview": "vite preview",
910
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
1011
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
1112
"lint": "eslint .",
1213
"lint-fix": "nr lint --fix"
1314
},
1415
"devDependencies": {
15-
"@sveltejs/adapter-static": "^1.0.0",
16-
"@sveltejs/kit": "^1.0.1",
16+
"@sveltejs/adapter-static": "^2.0.1",
17+
"@sveltejs/kit": "^1.11.0",
1718
"@types/cookie": "^0.5.1",
18-
"@typescript-eslint/eslint-plugin": "^5.51.0",
19-
"@typescript-eslint/parser": "^5.51.0",
19+
"@typescript-eslint/eslint-plugin": "^5.54.1",
20+
"@typescript-eslint/parser": "^5.54.1",
2021
"@vite-pwa/sveltekit": "workspace:*",
21-
"eslint": "^8.33.0",
22+
"eslint": "^8.35.0",
2223
"eslint-plugin-svelte3": "^4.0.0",
23-
"svelte": "^3.54.0",
24-
"svelte-check": "^2.10.2",
25-
"svelte-preprocess": "^5.0.0",
26-
"tslib": "^2.4.1",
24+
"svelte": "^3.55.1",
25+
"svelte-check": "^3.1.0",
26+
"svelte-preprocess": "^5.0.1",
27+
"tslib": "^2.5.0",
2728
"typescript": "^4.9.5",
28-
"vite": "^4.0.0"
29+
"vite": "^4.1.4"
2930
},
3031
"type": "module",
3132
"dependencies": {

examples/sveltekit-ts/pwa.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const generateSW = true;

examples/sveltekit-ts/src/prompt-sw.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/// <reference lib="WebWorker" />
2+
/// <reference types="vite/client" />
3+
/// <reference no-default-lib="true"/>
4+
/// <reference lib="esnext" />
15
import { cleanupOutdatedCaches, createHandlerBoundToURL, precacheAndRoute } from 'workbox-precaching'
26
import { NavigationRoute, registerRoute } from 'workbox-routing'
37

examples/sveltekit-ts/svelte.config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import adapter from '@sveltejs/adapter-static';
22
import preprocess from 'svelte-preprocess';
3+
// you don't need to do this if you're using generateSW strategy in your app
4+
import { generateSW } from './pwa.mjs';
35

46
/** @type {import('@sveltejs/kit').Config} */
57
const config = {
@@ -8,7 +10,14 @@ const config = {
810
preprocess: preprocess(),
911

1012
kit: {
11-
adapter: adapter()
13+
adapter: adapter(),
14+
serviceWorker: {
15+
register: false,
16+
},
17+
files: {
18+
// you don't need to do this if you're using generateSW strategy in your app
19+
serviceWorker: generateSW ? undefined : 'src/prompt-sw.ts',
20+
}
1221
}
1322
};
1423

examples/sveltekit-ts/vite.config.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import { sveltekit } from '@sveltejs/kit/vite';
22
import type { UserConfig } from 'vite';
33
import { SvelteKitPWA } from '@vite-pwa/sveltekit';
4+
// you don't need to do this if you're using generateSW strategy in your app
5+
import { generateSW } from './pwa.mjs';
46

57
const config: UserConfig = {
8+
// WARN: this will not be necessary on your project
69
logLevel: 'info',
10+
// WARN: this will not be necessary on your project
711
build: {
812
minify: false,
913
},
14+
// WARN: this will not be necessary on your project
1015
define: {
1116
__DATE__: `'${new Date().toISOString()}'`,
1217
__RELOAD_SW__: false,
18+
'process.env.NODE_ENV': process.env.NODE_ENV === 'production' ? '"production"' : '"development"',
1319
},
1420
// WARN: this will not be necessary on your project
1521
server: {
@@ -23,10 +29,13 @@ const config: UserConfig = {
2329
SvelteKitPWA({
2430
srcDir: './src',
2531
mode: 'development',
26-
strategies: 'injectManifest',
27-
filename: 'prompt-sw.ts',
32+
// you don't need to do this if you're using generateSW strategy in your app
33+
strategies: generateSW ? 'generateSW' : 'injectManifest',
34+
// you don't need to do this if you're using generateSW strategy in your app
35+
filename: generateSW ? undefined : 'prompt-sw.ts',
2836
scope: '/',
2937
base: '/',
38+
selfDestroying: process.env.SELF_DESTROYING_SW === 'true',
3039
manifest: {
3140
short_name: 'SvelteKit PWA',
3241
name: 'SvelteKit PWA',
@@ -57,6 +66,9 @@ const config: UserConfig = {
5766
injectManifest: {
5867
globPatterns: ['client/**/*.{js,css,ico,png,svg,webp,woff,woff2}']
5968
},
69+
workbox: {
70+
globPatterns: ['client/**/*.{js,css,ico,png,svg,webp,woff,woff2}']
71+
},
6072
devOptions: {
6173
enabled: true,
6274
type: 'module',
@@ -65,7 +77,8 @@ const config: UserConfig = {
6577
// if you have shared info in svelte config file put in a separate module and use it also here
6678
kit: {}
6779
}
68-
)]
80+
)
81+
]
6982
};
7083

7184
export default config;

package.json

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@vite-pwa/sveltekit",
33
"type": "module",
44
"version": "0.1.3",
5-
"packageManager": "pnpm@7.26.1",
5+
"packageManager": "pnpm@7.29.1",
66
"description": "Zero-config PWA for SvelteKit",
77
"author": "antfu <anthonyfu117@hotmail.com>",
88
"license": "MIT",
@@ -49,22 +49,24 @@
4949
"release": "bumpp && npm publish"
5050
},
5151
"peerDependencies": {
52-
"@sveltejs/kit": "^1.0.0",
52+
"@sveltejs/kit": "^1.3.1",
5353
"vite-plugin-pwa": "^0.14.0"
5454
},
5555
"devDependencies": {
56-
"@antfu/eslint-config": "^0.35.2",
57-
"@antfu/ni": "^0.19.0",
56+
"@antfu/eslint-config": "^0.36.0",
57+
"@antfu/ni": "^0.20.0",
5858
"@types/debug": "^4.1.7",
59-
"@types/node": "^18.13.0",
59+
"@types/node": "^18.14.6",
6060
"@types/workbox-build": "^5.0.1",
61-
"@typescript-eslint/eslint-plugin": "^5.51.0",
61+
"@typescript-eslint/eslint-plugin": "^5.54.1",
62+
"@vite-pwa/sveltekit": "workspace:*",
6263
"bumpp": "^8.2.1",
63-
"eslint": "^8.33.0",
64-
"svelte": "^3.54.0",
64+
"eslint": "^8.35.0",
65+
"kolorist": "^1.6.0",
66+
"svelte": "^3.55.1",
6567
"typescript": "^4.9.5",
66-
"unbuild": "^1.1.1",
67-
"vite": "^4.0.0",
68-
"vite-plugin-pwa": "^0.14.2"
68+
"unbuild": "^1.1.2",
69+
"vite": "^4.1.4",
70+
"vite-plugin-pwa": "^0.14.4"
6971
}
7072
}

0 commit comments

Comments
 (0)