@serwist/vite 9.0.0-preview.14 → 9.0.0-preview.16

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.
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import { validationErrorMap, SerwistConfigError } from '@serwist/build/schema';
7
7
  import { normalizePath } from 'vite';
8
8
  import process from 'node:process';
9
9
 
10
- var version = "9.0.0-preview.14";
10
+ var version = "9.0.0-preview.16";
11
11
 
12
12
  const logSerwistResult = (buildResult, viteOptions)=>{
13
13
  const { logLevel = "info" } = viteOptions;
@@ -1,11 +1,9 @@
1
- import { CacheFirst, NetworkFirst } from "@serwist/strategies";
2
- export declare const defaultCache: ({
3
- matcher: RegExp;
4
- handler: CacheFirst;
5
- method?: undefined;
6
- } | {
7
- matcher: RegExp;
8
- method: "GET";
9
- handler: NetworkFirst;
10
- })[];
1
+ import type { RuntimeCaching } from "@serwist/sw";
2
+ /**
3
+ * The default, recommended list of caching strategies for applications
4
+ * built with Vite.
5
+ *
6
+ * @see https://serwist.pages.dev/docs/vite/worker-exports#default-cache
7
+ */
8
+ export declare const defaultCache: RuntimeCaching[];
11
9
  //# sourceMappingURL=index.worker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.worker.d.ts","sourceRoot":"","sources":["../src/index.worker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAwB,MAAM,qBAAqB,CAAC;AAGrF,eAAO,MAAM,YAAY;;;;;;;;IAoGG,CAAC"}
1
+ {"version":3,"file":"index.worker.d.ts","sourceRoot":"","sources":["../src/index.worker.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD;;;;;GAKG;AACH,eAAO,MAAM,YAAY,EAAE,cAAc,EA8GpC,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { ExpirationPlugin } from '@serwist/expiration';
2
2
  import { CacheFirst, StaleWhileRevalidate, NetworkFirst } from '@serwist/strategies';
3
3
 
4
- const defaultCache = [
4
+ const defaultCache = import.meta.env.DEV ? [] : [
5
5
  {
6
6
  matcher: /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i,
7
7
  handler: new CacheFirst({
@@ -9,7 +9,8 @@ const defaultCache = [
9
9
  plugins: [
10
10
  new ExpirationPlugin({
11
11
  maxEntries: 4,
12
- maxAgeSeconds: 365 * 24 * 60 * 60
12
+ maxAgeSeconds: 365 * 24 * 60 * 60,
13
+ maxAgeFrom: "last-used"
13
14
  })
14
15
  ]
15
16
  })
@@ -21,7 +22,8 @@ const defaultCache = [
21
22
  plugins: [
22
23
  new ExpirationPlugin({
23
24
  maxEntries: 4,
24
- maxAgeSeconds: 7 * 24 * 60 * 60
25
+ maxAgeSeconds: 7 * 24 * 60 * 60,
26
+ maxAgeFrom: "last-used"
25
27
  })
26
28
  ]
27
29
  })
@@ -33,7 +35,8 @@ const defaultCache = [
33
35
  plugins: [
34
36
  new ExpirationPlugin({
35
37
  maxEntries: 64,
36
- maxAgeSeconds: 24 * 60 * 60
38
+ maxAgeSeconds: 24 * 60 * 60,
39
+ maxAgeFrom: "last-used"
37
40
  })
38
41
  ]
39
42
  })
@@ -45,7 +48,8 @@ const defaultCache = [
45
48
  plugins: [
46
49
  new ExpirationPlugin({
47
50
  maxEntries: 32,
48
- maxAgeSeconds: 24 * 60 * 60
51
+ maxAgeSeconds: 24 * 60 * 60,
52
+ maxAgeFrom: "last-used"
49
53
  })
50
54
  ]
51
55
  })
@@ -57,7 +61,8 @@ const defaultCache = [
57
61
  plugins: [
58
62
  new ExpirationPlugin({
59
63
  maxEntries: 32,
60
- maxAgeSeconds: 24 * 60 * 60
64
+ maxAgeSeconds: 24 * 60 * 60,
65
+ maxAgeFrom: "last-used"
61
66
  })
62
67
  ]
63
68
  })
@@ -69,7 +74,8 @@ const defaultCache = [
69
74
  plugins: [
70
75
  new ExpirationPlugin({
71
76
  maxEntries: 32,
72
- maxAgeSeconds: 24 * 60 * 60
77
+ maxAgeSeconds: 24 * 60 * 60,
78
+ maxAgeFrom: "last-used"
73
79
  })
74
80
  ]
75
81
  })
@@ -82,7 +88,8 @@ const defaultCache = [
82
88
  plugins: [
83
89
  new ExpirationPlugin({
84
90
  maxEntries: 16,
85
- maxAgeSeconds: 24 * 60 * 60
91
+ maxAgeSeconds: 24 * 60 * 60,
92
+ maxAgeFrom: "last-used"
86
93
  })
87
94
  ],
88
95
  networkTimeoutSeconds: 10
@@ -95,7 +102,8 @@ const defaultCache = [
95
102
  plugins: [
96
103
  new ExpirationPlugin({
97
104
  maxEntries: 32,
98
- maxAgeSeconds: 24 * 60 * 60
105
+ maxAgeSeconds: 24 * 60 * 60,
106
+ maxAgeFrom: "last-used"
99
107
  })
100
108
  ],
101
109
  networkTimeoutSeconds: 10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/vite",
3
- "version": "9.0.0-preview.14",
3
+ "version": "9.0.0-preview.16",
4
4
  "type": "module",
5
5
  "description": "A module that integrates Serwist into your Vite application.",
6
6
  "files": [
@@ -72,24 +72,24 @@
72
72
  "glob": "10.3.10",
73
73
  "kolorist": "1.8.0",
74
74
  "zod": "3.22.4",
75
- "@serwist/build": "9.0.0-preview.14",
76
- "@serwist/expiration": "9.0.0-preview.14",
77
- "@serwist/strategies": "9.0.0-preview.14",
78
- "@serwist/window": "9.0.0-preview.14"
75
+ "@serwist/build": "9.0.0-preview.16",
76
+ "@serwist/expiration": "9.0.0-preview.16",
77
+ "@serwist/strategies": "9.0.0-preview.16",
78
+ "@serwist/window": "9.0.0-preview.16"
79
79
  },
80
80
  "devDependencies": {
81
- "@types/node": "20.11.26",
81
+ "@types/node": "20.11.30",
82
82
  "rollup": "4.13.0",
83
- "typescript": "5.5.0-dev.20240312",
84
- "vite": "5.1.6",
85
- "@serwist/constants": "9.0.0-preview.14",
86
- "@serwist/sw": "9.0.0-preview.14",
87
- "@serwist/utils": "9.0.0-preview.14"
83
+ "typescript": "5.5.0-dev.20240323",
84
+ "vite": "5.2.4",
85
+ "@serwist/constants": "9.0.0-preview.16",
86
+ "@serwist/sw": "9.0.0-preview.16",
87
+ "@serwist/utils": "9.0.0-preview.16"
88
88
  },
89
89
  "peerDependencies": {
90
90
  "typescript": ">=5.0.0",
91
91
  "vite": "^5.0.0",
92
- "@serwist/sw": "9.0.0-preview.14"
92
+ "@serwist/sw": "9.0.0-preview.16"
93
93
  },
94
94
  "peerDependenciesMeta": {
95
95
  "@serwist/sw": {
@@ -2,104 +2,120 @@ import { ExpirationPlugin } from "@serwist/expiration";
2
2
  import { CacheFirst, NetworkFirst, StaleWhileRevalidate } from "@serwist/strategies";
3
3
  import type { RuntimeCaching } from "@serwist/sw";
4
4
 
5
- export const defaultCache = [
6
- {
7
- matcher: /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i,
8
- handler: new CacheFirst({
9
- cacheName: "google-fonts",
10
- plugins: [
11
- new ExpirationPlugin({
12
- maxEntries: 4,
13
- maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days
5
+ /**
6
+ * The default, recommended list of caching strategies for applications
7
+ * built with Vite.
8
+ *
9
+ * @see https://serwist.pages.dev/docs/vite/worker-exports#default-cache
10
+ */
11
+ export const defaultCache: RuntimeCaching[] = import.meta.env.DEV
12
+ ? []
13
+ : [
14
+ {
15
+ matcher: /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i,
16
+ handler: new CacheFirst({
17
+ cacheName: "google-fonts",
18
+ plugins: [
19
+ new ExpirationPlugin({
20
+ maxEntries: 4,
21
+ maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days
22
+ maxAgeFrom: "last-used",
23
+ }),
24
+ ],
14
25
  }),
15
- ],
16
- }),
17
- },
18
- {
19
- matcher: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
20
- handler: new StaleWhileRevalidate({
21
- cacheName: "static-font-assets",
22
- plugins: [
23
- new ExpirationPlugin({
24
- maxEntries: 4,
25
- maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
26
+ },
27
+ {
28
+ matcher: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
29
+ handler: new StaleWhileRevalidate({
30
+ cacheName: "static-font-assets",
31
+ plugins: [
32
+ new ExpirationPlugin({
33
+ maxEntries: 4,
34
+ maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
35
+ maxAgeFrom: "last-used",
36
+ }),
37
+ ],
26
38
  }),
27
- ],
28
- }),
29
- },
30
- {
31
- matcher: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
32
- handler: new StaleWhileRevalidate({
33
- cacheName: "static-image-assets",
34
- plugins: [
35
- new ExpirationPlugin({
36
- maxEntries: 64,
37
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
39
+ },
40
+ {
41
+ matcher: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
42
+ handler: new StaleWhileRevalidate({
43
+ cacheName: "static-image-assets",
44
+ plugins: [
45
+ new ExpirationPlugin({
46
+ maxEntries: 64,
47
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
48
+ maxAgeFrom: "last-used",
49
+ }),
50
+ ],
38
51
  }),
39
- ],
40
- }),
41
- },
42
- {
43
- matcher: /\.(?:js)$/i,
44
- handler: new StaleWhileRevalidate({
45
- cacheName: "static-js-assets",
46
- plugins: [
47
- new ExpirationPlugin({
48
- maxEntries: 32,
49
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
52
+ },
53
+ {
54
+ matcher: /\.(?:js)$/i,
55
+ handler: new StaleWhileRevalidate({
56
+ cacheName: "static-js-assets",
57
+ plugins: [
58
+ new ExpirationPlugin({
59
+ maxEntries: 32,
60
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
61
+ maxAgeFrom: "last-used",
62
+ }),
63
+ ],
50
64
  }),
51
- ],
52
- }),
53
- },
54
- {
55
- matcher: /\.(?:css|less)$/i,
56
- handler: new StaleWhileRevalidate({
57
- cacheName: "static-style-assets",
58
- plugins: [
59
- new ExpirationPlugin({
60
- maxEntries: 32,
61
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
65
+ },
66
+ {
67
+ matcher: /\.(?:css|less)$/i,
68
+ handler: new StaleWhileRevalidate({
69
+ cacheName: "static-style-assets",
70
+ plugins: [
71
+ new ExpirationPlugin({
72
+ maxEntries: 32,
73
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
74
+ maxAgeFrom: "last-used",
75
+ }),
76
+ ],
62
77
  }),
63
- ],
64
- }),
65
- },
66
- {
67
- matcher: /\.(?:json|xml|csv)$/i,
68
- handler: new NetworkFirst({
69
- cacheName: "static-data-assets",
70
- plugins: [
71
- new ExpirationPlugin({
72
- maxEntries: 32,
73
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
78
+ },
79
+ {
80
+ matcher: /\.(?:json|xml|csv)$/i,
81
+ handler: new NetworkFirst({
82
+ cacheName: "static-data-assets",
83
+ plugins: [
84
+ new ExpirationPlugin({
85
+ maxEntries: 32,
86
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
87
+ maxAgeFrom: "last-used",
88
+ }),
89
+ ],
74
90
  }),
75
- ],
76
- }),
77
- },
78
- {
79
- matcher: /\/api\/.*$/i,
80
- method: "GET",
81
- handler: new NetworkFirst({
82
- cacheName: "apis",
83
- plugins: [
84
- new ExpirationPlugin({
85
- maxEntries: 16,
86
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
91
+ },
92
+ {
93
+ matcher: /\/api\/.*$/i,
94
+ method: "GET",
95
+ handler: new NetworkFirst({
96
+ cacheName: "apis",
97
+ plugins: [
98
+ new ExpirationPlugin({
99
+ maxEntries: 16,
100
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
101
+ maxAgeFrom: "last-used",
102
+ }),
103
+ ],
104
+ networkTimeoutSeconds: 10, // fallback to cache if API does not response within 10 seconds
87
105
  }),
88
- ],
89
- networkTimeoutSeconds: 10, // fallback to cache if API does not response within 10 seconds
90
- }),
91
- },
92
- {
93
- matcher: /.*/i,
94
- handler: new NetworkFirst({
95
- cacheName: "others",
96
- plugins: [
97
- new ExpirationPlugin({
98
- maxEntries: 32,
99
- maxAgeSeconds: 24 * 60 * 60, // 24 hours
106
+ },
107
+ {
108
+ matcher: /.*/i,
109
+ handler: new NetworkFirst({
110
+ cacheName: "others",
111
+ plugins: [
112
+ new ExpirationPlugin({
113
+ maxEntries: 32,
114
+ maxAgeSeconds: 24 * 60 * 60, // 24 hours
115
+ maxAgeFrom: "last-used",
116
+ }),
117
+ ],
118
+ networkTimeoutSeconds: 10,
100
119
  }),
101
- ],
102
- networkTimeoutSeconds: 10,
103
- }),
104
- },
105
- ] satisfies RuntimeCaching[];
120
+ },
121
+ ];