@serwist/vite 9.0.0-preview.1 → 9.0.0-preview.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,94 +1,105 @@
1
+ import { ExpirationPlugin } from '@serwist/expiration';
2
+ import { CacheFirst, StaleWhileRevalidate, NetworkFirst } from '@serwist/strategies';
3
+
1
4
  const defaultCache = [
2
5
  {
3
- urlPattern: /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i,
4
- handler: "CacheFirst",
5
- options: {
6
+ matcher: /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i,
7
+ handler: new CacheFirst({
6
8
  cacheName: "google-fonts",
7
- expiration: {
8
- maxEntries: 4,
9
- maxAgeSeconds: 365 * 24 * 60 * 60
10
- }
11
- }
9
+ plugins: [
10
+ new ExpirationPlugin({
11
+ maxEntries: 4,
12
+ maxAgeSeconds: 365 * 24 * 60 * 60
13
+ })
14
+ ]
15
+ })
12
16
  },
13
17
  {
14
- urlPattern: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
15
- handler: "StaleWhileRevalidate",
16
- options: {
18
+ matcher: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
19
+ handler: new StaleWhileRevalidate({
17
20
  cacheName: "static-font-assets",
18
- expiration: {
19
- maxEntries: 4,
20
- maxAgeSeconds: 7 * 24 * 60 * 60
21
- }
22
- }
21
+ plugins: [
22
+ new ExpirationPlugin({
23
+ maxEntries: 4,
24
+ maxAgeSeconds: 7 * 24 * 60 * 60
25
+ })
26
+ ]
27
+ })
23
28
  },
24
29
  {
25
- urlPattern: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
26
- handler: "StaleWhileRevalidate",
27
- options: {
30
+ matcher: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
31
+ handler: new StaleWhileRevalidate({
28
32
  cacheName: "static-image-assets",
29
- expiration: {
30
- maxEntries: 64,
31
- maxAgeSeconds: 24 * 60 * 60
32
- }
33
- }
33
+ plugins: [
34
+ new ExpirationPlugin({
35
+ maxEntries: 64,
36
+ maxAgeSeconds: 24 * 60 * 60
37
+ })
38
+ ]
39
+ })
34
40
  },
35
41
  {
36
- urlPattern: /\.(?:js)$/i,
37
- handler: "StaleWhileRevalidate",
38
- options: {
42
+ matcher: /\.(?:js)$/i,
43
+ handler: new StaleWhileRevalidate({
39
44
  cacheName: "static-js-assets",
40
- expiration: {
41
- maxEntries: 32,
42
- maxAgeSeconds: 24 * 60 * 60
43
- }
44
- }
45
+ plugins: [
46
+ new ExpirationPlugin({
47
+ maxEntries: 32,
48
+ maxAgeSeconds: 24 * 60 * 60
49
+ })
50
+ ]
51
+ })
45
52
  },
46
53
  {
47
- urlPattern: /\.(?:css|less)$/i,
48
- handler: "StaleWhileRevalidate",
49
- options: {
54
+ matcher: /\.(?:css|less)$/i,
55
+ handler: new StaleWhileRevalidate({
50
56
  cacheName: "static-style-assets",
51
- expiration: {
52
- maxEntries: 32,
53
- maxAgeSeconds: 24 * 60 * 60
54
- }
55
- }
57
+ plugins: [
58
+ new ExpirationPlugin({
59
+ maxEntries: 32,
60
+ maxAgeSeconds: 24 * 60 * 60
61
+ })
62
+ ]
63
+ })
56
64
  },
57
65
  {
58
- urlPattern: /\.(?:json|xml|csv)$/i,
59
- handler: "NetworkFirst",
60
- options: {
66
+ matcher: /\.(?:json|xml|csv)$/i,
67
+ handler: new NetworkFirst({
61
68
  cacheName: "static-data-assets",
62
- expiration: {
63
- maxEntries: 32,
64
- maxAgeSeconds: 24 * 60 * 60
65
- }
66
- }
69
+ plugins: [
70
+ new ExpirationPlugin({
71
+ maxEntries: 32,
72
+ maxAgeSeconds: 24 * 60 * 60
73
+ })
74
+ ]
75
+ })
67
76
  },
68
77
  {
69
- urlPattern: /\/api\/.*$/i,
70
- handler: "NetworkFirst",
78
+ matcher: /\/api\/.*$/i,
71
79
  method: "GET",
72
- options: {
80
+ handler: new NetworkFirst({
73
81
  cacheName: "apis",
74
- expiration: {
75
- maxEntries: 16,
76
- maxAgeSeconds: 24 * 60 * 60
77
- },
82
+ plugins: [
83
+ new ExpirationPlugin({
84
+ maxEntries: 16,
85
+ maxAgeSeconds: 24 * 60 * 60
86
+ })
87
+ ],
78
88
  networkTimeoutSeconds: 10
79
- }
89
+ })
80
90
  },
81
91
  {
82
- urlPattern: /.*/i,
83
- handler: "NetworkFirst",
84
- options: {
92
+ matcher: /.*/i,
93
+ handler: new NetworkFirst({
85
94
  cacheName: "others",
86
- expiration: {
87
- maxEntries: 32,
88
- maxAgeSeconds: 24 * 60 * 60
89
- },
95
+ plugins: [
96
+ new ExpirationPlugin({
97
+ maxEntries: 32,
98
+ maxAgeSeconds: 24 * 60 * 60
99
+ })
100
+ ],
90
101
  networkTimeoutSeconds: 10
91
- }
102
+ })
92
103
  }
93
104
  ];
94
105
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/vite",
3
- "version": "9.0.0-preview.1",
3
+ "version": "9.0.0-preview.10",
4
4
  "type": "module",
5
5
  "description": "A module that integrates Serwist into your Vite application.",
6
6
  "files": [
@@ -43,9 +43,6 @@
43
43
  ],
44
44
  "worker": [
45
45
  "./dist/index.worker.d.ts"
46
- ],
47
- "integration-*": [
48
- "./dist/integration/*/index.d.ts"
49
46
  ]
50
47
  }
51
48
  },
@@ -62,18 +59,16 @@
62
59
  "types": "./dist/index.worker.d.ts",
63
60
  "default": "./dist/index.worker.js"
64
61
  },
65
- "./integration-*": {
66
- "types": "./dist/integration/*/index.d.ts",
67
- "default": "./dist/integration/*/index.js"
68
- },
69
62
  "./package.json": "./package.json"
70
63
  },
71
64
  "dependencies": {
72
65
  "debug": "4.3.4",
73
66
  "fast-glob": "3.3.2",
74
67
  "pretty-bytes": "6.1.1",
75
- "@serwist/build": "9.0.0-preview.1",
76
- "@serwist/window": "9.0.0-preview.1"
68
+ "@serwist/build": "9.0.0-preview.10",
69
+ "@serwist/expiration": "9.0.0-preview.10",
70
+ "@serwist/strategies": "9.0.0-preview.10",
71
+ "@serwist/window": "9.0.0-preview.10"
77
72
  },
78
73
  "devDependencies": {
79
74
  "@playwright/test": "1.41.2",
@@ -81,7 +76,7 @@
81
76
  "@types/debug": "4.1.12",
82
77
  "@types/node": "20.11.16",
83
78
  "@types/prompts": "2.4.9",
84
- "@types/react": "18.2.52",
79
+ "@types/react": "18.2.54",
85
80
  "bumpp": "9.3.0",
86
81
  "kolorist": "1.8.0",
87
82
  "preact": "10.19.3",
@@ -89,13 +84,13 @@
89
84
  "publint": "0.2.7",
90
85
  "react": "18.2.0",
91
86
  "rollup": "4.9.6",
92
- "solid-js": "1.8.12",
93
- "svelte": "5.0.0-next.45",
94
- "typescript": "5.4.0-dev.20240203",
87
+ "solid-js": "1.8.14",
88
+ "svelte": "5.0.0-next.48",
89
+ "typescript": "5.4.0-dev.20240206",
95
90
  "vite": "5.0.12",
96
91
  "vue": "3.4.15",
97
- "@serwist/constants": "9.0.0-preview.1",
98
- "@serwist/sw": "9.0.0-preview.1"
92
+ "@serwist/constants": "9.0.0-preview.10",
93
+ "@serwist/sw": "9.0.0-preview.10"
99
94
  },
100
95
  "peerDependencies": {
101
96
  "@sveltejs/kit": "^1.0.0 || ^2.0.0",
@@ -106,7 +101,7 @@
106
101
  "typescript": ">=5.0.0",
107
102
  "vite": "^5.0.0",
108
103
  "vue": "^3.0.0",
109
- "@serwist/sw": "9.0.0-preview.1"
104
+ "@serwist/sw": "9.0.0-preview.10"
110
105
  },
111
106
  "peerDependenciesMeta": {
112
107
  "@serwist/sw": {
package/src/context.ts CHANGED
@@ -2,7 +2,7 @@ import type { ResolvedConfig } from "vite";
2
2
 
3
3
  import type { PluginOptions, ResolvedPluginOptions } from "./types.js";
4
4
 
5
- export type SerwistViteFrameworks = "nuxt" | "sveltekit";
5
+ export type SerwistViteFrameworks = "nuxt";
6
6
 
7
7
  export interface SerwistViteContext {
8
8
  /**
@@ -1,95 +1,105 @@
1
+ import { ExpirationPlugin } from "@serwist/expiration";
2
+ import { CacheFirst, NetworkFirst, StaleWhileRevalidate } from "@serwist/strategies";
1
3
  import type { RuntimeCaching } from "@serwist/sw";
2
4
 
3
- export const defaultCache: RuntimeCaching[] = [
5
+ export const defaultCache = [
4
6
  {
5
- urlPattern: /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i,
6
- handler: "CacheFirst",
7
- options: {
7
+ matcher: /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i,
8
+ handler: new CacheFirst({
8
9
  cacheName: "google-fonts",
9
- expiration: {
10
- maxEntries: 4,
11
- maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days
12
- },
13
- },
10
+ plugins: [
11
+ new ExpirationPlugin({
12
+ maxEntries: 4,
13
+ maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days
14
+ }),
15
+ ],
16
+ }),
14
17
  },
15
18
  {
16
- urlPattern: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
17
- handler: "StaleWhileRevalidate",
18
- options: {
19
+ matcher: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
20
+ handler: new StaleWhileRevalidate({
19
21
  cacheName: "static-font-assets",
20
- expiration: {
21
- maxEntries: 4,
22
- maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
23
- },
24
- },
22
+ plugins: [
23
+ new ExpirationPlugin({
24
+ maxEntries: 4,
25
+ maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
26
+ }),
27
+ ],
28
+ }),
25
29
  },
26
30
  {
27
- urlPattern: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
28
- handler: "StaleWhileRevalidate",
29
- options: {
31
+ matcher: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
32
+ handler: new StaleWhileRevalidate({
30
33
  cacheName: "static-image-assets",
31
- expiration: {
32
- maxEntries: 64,
33
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
34
- },
35
- },
34
+ plugins: [
35
+ new ExpirationPlugin({
36
+ maxEntries: 64,
37
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
38
+ }),
39
+ ],
40
+ }),
36
41
  },
37
42
  {
38
- urlPattern: /\.(?:js)$/i,
39
- handler: "StaleWhileRevalidate",
40
- options: {
43
+ matcher: /\.(?:js)$/i,
44
+ handler: new StaleWhileRevalidate({
41
45
  cacheName: "static-js-assets",
42
- expiration: {
43
- maxEntries: 32,
44
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
45
- },
46
- },
46
+ plugins: [
47
+ new ExpirationPlugin({
48
+ maxEntries: 32,
49
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
50
+ }),
51
+ ],
52
+ }),
47
53
  },
48
54
  {
49
- urlPattern: /\.(?:css|less)$/i,
50
- handler: "StaleWhileRevalidate",
51
- options: {
55
+ matcher: /\.(?:css|less)$/i,
56
+ handler: new StaleWhileRevalidate({
52
57
  cacheName: "static-style-assets",
53
- expiration: {
54
- maxEntries: 32,
55
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
56
- },
57
- },
58
+ plugins: [
59
+ new ExpirationPlugin({
60
+ maxEntries: 32,
61
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
62
+ }),
63
+ ],
64
+ }),
58
65
  },
59
66
  {
60
- urlPattern: /\.(?:json|xml|csv)$/i,
61
- handler: "NetworkFirst",
62
- options: {
67
+ matcher: /\.(?:json|xml|csv)$/i,
68
+ handler: new NetworkFirst({
63
69
  cacheName: "static-data-assets",
64
- expiration: {
65
- maxEntries: 32,
66
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
67
- },
68
- },
70
+ plugins: [
71
+ new ExpirationPlugin({
72
+ maxEntries: 32,
73
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
74
+ }),
75
+ ],
76
+ }),
69
77
  },
70
78
  {
71
- urlPattern: /\/api\/.*$/i,
72
- handler: "NetworkFirst",
79
+ matcher: /\/api\/.*$/i,
73
80
  method: "GET",
74
- options: {
81
+ handler: new NetworkFirst({
75
82
  cacheName: "apis",
76
- expiration: {
77
- maxEntries: 16,
78
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
79
- },
83
+ plugins: [
84
+ new ExpirationPlugin({
85
+ maxEntries: 16,
86
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
87
+ }),
88
+ ],
80
89
  networkTimeoutSeconds: 10, // fallback to cache if API does not response within 10 seconds
81
- },
90
+ }),
82
91
  },
83
92
  {
84
- urlPattern: /.*/i,
85
- handler: "NetworkFirst",
86
- options: {
93
+ matcher: /.*/i,
94
+ handler: new NetworkFirst({
87
95
  cacheName: "others",
88
- expiration: {
89
- maxEntries: 32,
90
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
91
- },
96
+ plugins: [
97
+ new ExpirationPlugin({
98
+ maxEntries: 32,
99
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
100
+ }),
101
+ ],
92
102
  networkTimeoutSeconds: 10,
93
- },
103
+ }),
94
104
  },
95
- ];
105
+ ] satisfies RuntimeCaching[];
package/src/modules.ts CHANGED
@@ -50,7 +50,7 @@ export const generateServiceWorker = async (ctx: SerwistViteContext) => {
50
50
  const isProduction = ctx.options.mode === "production";
51
51
  const isDev = ctx.options.mode === "development";
52
52
 
53
- if ((isProduction && ctx.framework === "sveltekit") || (isDev && !ctx.options.devOptions.bundle)) {
53
+ if (isDev && !ctx.options.devOptions.bundle) {
54
54
  if (!injectManifestResult) {
55
55
  throw new Error("injectManifest failed to generate results. This is likely a bug.");
56
56
  }
package/src/options.ts CHANGED
@@ -11,7 +11,7 @@ import { resolveBasePath, slash } from "./utils.js";
11
11
  export const resolveOptions = async (options: PluginOptions, viteConfig: ResolvedConfig): Promise<ResolvedPluginOptions> => {
12
12
  const {
13
13
  type = "classic",
14
- mode = (process.env.NODE_ENV || "production") as "production" | "development",
14
+ mode = process.env.NODE_ENV === "production" || process.env.NODE_ENV === "development" ? process.env.NODE_ENV : "production",
15
15
  injectRegister = "auto",
16
16
  registerType = "prompt",
17
17
  minify = true,
package/src/rollup.js CHANGED
@@ -1,28 +1,8 @@
1
1
  // @ts-check
2
- import path from "node:path";
3
- import { fileURLToPath } from "node:url";
4
-
5
2
  import { getRollupOptions } from "@serwist/constants/rollup";
6
- import fg from "fast-glob";
7
3
 
8
4
  import packageJson from "../package.json" assert { type: "json" };
9
5
 
10
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
-
12
- const clientEntries = /** @type {Record<string, string>} */ ({});
13
-
14
- for (const clientPath of await fg("client/*.ts", { cwd: __dirname })) {
15
- const parsedClientPath = path.parse(clientPath);
16
- clientEntries[`client/${parsedClientPath.name}`] = path.join("src", clientPath);
17
- }
18
-
19
- const integrationEntries = /** @type {Record<string, string>} */ ({});
20
-
21
- for (const integrationPath of await fg("integration/*/index.ts", { cwd: __dirname })) {
22
- const parsedClientPath = path.parse(integrationPath);
23
- integrationEntries[`${parsedClientPath.dir}/${parsedClientPath.name}`] = path.join("src", integrationPath);
24
- }
25
-
26
6
  export default getRollupOptions({
27
7
  packageJson,
28
8
  jsFiles: [
@@ -31,8 +11,6 @@ export default getRollupOptions({
31
11
  index: "src/index.ts",
32
12
  "index.browser": "src/index.browser.ts",
33
13
  "index.worker": "src/index.worker.ts",
34
- ...clientEntries,
35
- ...integrationEntries,
36
14
  },
37
15
  output: {
38
16
  dir: "dist",
@@ -1,5 +0,0 @@
1
- import type { Plugin } from "vite";
2
- import type { SerwistViteContext } from "../../context.js";
3
- import type { SerwistViteApi } from "../../types.js";
4
- export declare const buildPlugin: (ctx: SerwistViteContext, api: SerwistViteApi) => Plugin<any>;
5
- //# sourceMappingURL=build.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/integration/svelte/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,eAAO,MAAM,WAAW,QAAS,kBAAkB,OAAO,cAAc,gBAevE,CAAC"}
@@ -1,9 +0,0 @@
1
- import type { ManifestTransform } from "@serwist/build";
2
- import type { ResolvedConfig } from "vite";
3
- import type { PluginOptions as BasePluginOptions } from "../../types.js";
4
- import type { KitOptions } from "./types.js";
5
- export declare const configurateSvelteKitOptions: (viteConfig: ResolvedConfig, kit: KitOptions, options: BasePluginOptions) => void;
6
- export declare function createManifestTransform(base: string, webManifestName?: string, options?: KitOptions): ManifestTransform;
7
- export declare function buildGlobPatterns(globPatterns?: string[]): string[];
8
- export declare function buildGlobIgnores(globIgnores?: string[]): string[];
9
- //# sourceMappingURL=config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/integration/svelte/config.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAE3C,OAAO,KAAK,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEzE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,eAAO,MAAM,2BAA2B,eAAgB,cAAc,OAAO,UAAU,WAAW,iBAAiB,SAiDlH,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,iBAAiB,CAqDvH;AAED,wBAAgB,iBAAiB,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,YAYxD;AAED,wBAAgB,gBAAgB,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,YAQtD"}
@@ -1,10 +0,0 @@
1
- import type { Plugin } from "vite";
2
- import type { PluginOptions } from "./types.js";
3
- /**
4
- * Integrates Serwist into your SvelteKit app.
5
- * @param userOptions
6
- * @returns
7
- */
8
- export declare const serwist: (userOptions?: PluginOptions) => Plugin[];
9
- export * from "./types.js";
10
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/integration/svelte/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AASnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD;;;;GAIG;AACH,eAAO,MAAM,OAAO,iBAAiB,aAAa,KAAQ,MAAM,EAO/D,CAAC;AAEF,cAAc,YAAY,CAAC"}