@serwist/vite 9.0.0-preview.2 → 9.0.0-preview.4

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,3 +1,11 @@
1
- import type { RuntimeCaching } from "@serwist/sw";
2
- export declare const defaultCache: RuntimeCaching[];
1
+ import { CacheFirst, NetworkFirst } from "@serwist/strategies";
2
+ export declare const defaultCache: ({
3
+ urlPattern: RegExp;
4
+ handler: CacheFirst;
5
+ method?: undefined;
6
+ } | {
7
+ urlPattern: RegExp;
8
+ method: "GET";
9
+ handler: NetworkFirst;
10
+ })[];
3
11
  //# sourceMappingURL=index.worker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.worker.d.ts","sourceRoot":"","sources":["../src/index.worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,eAAO,MAAM,YAAY,EAAE,cAAc,EA4FxC,CAAC"}
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,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
6
  urlPattern: /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i,
4
- handler: "CacheFirst",
5
- options: {
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
18
  urlPattern: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
15
- handler: "StaleWhileRevalidate",
16
- options: {
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
30
  urlPattern: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
26
- handler: "StaleWhileRevalidate",
27
- options: {
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
42
  urlPattern: /\.(?:js)$/i,
37
- handler: "StaleWhileRevalidate",
38
- options: {
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
54
  urlPattern: /\.(?:css|less)$/i,
48
- handler: "StaleWhileRevalidate",
49
- options: {
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
66
  urlPattern: /\.(?:json|xml|csv)$/i,
59
- handler: "NetworkFirst",
60
- options: {
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
78
  urlPattern: /\/api\/.*$/i,
70
- handler: "NetworkFirst",
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
92
  urlPattern: /.*/i,
83
- handler: "NetworkFirst",
84
- options: {
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/dist/main.js CHANGED
@@ -62,7 +62,7 @@ const green = kolorist(32, 39);
62
62
  const yellow = kolorist(33, 39);
63
63
  const cyan = kolorist(36, 39);
64
64
 
65
- var version = "9.0.0-preview.2";
65
+ var version = "9.0.0-preview.4";
66
66
 
67
67
  const logSerwistResult = (buildResult, viteOptions)=>{
68
68
  const { logLevel = "info" } = viteOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/vite",
3
- "version": "9.0.0-preview.2",
3
+ "version": "9.0.0-preview.4",
4
4
  "type": "module",
5
5
  "description": "A module that integrates Serwist into your Vite application.",
6
6
  "files": [
@@ -72,8 +72,10 @@
72
72
  "debug": "4.3.4",
73
73
  "fast-glob": "3.3.2",
74
74
  "pretty-bytes": "6.1.1",
75
- "@serwist/build": "9.0.0-preview.2",
76
- "@serwist/window": "9.0.0-preview.2"
75
+ "@serwist/build": "9.0.0-preview.4",
76
+ "@serwist/expiration": "9.0.0-preview.4",
77
+ "@serwist/strategies": "9.0.0-preview.4",
78
+ "@serwist/window": "9.0.0-preview.4"
77
79
  },
78
80
  "devDependencies": {
79
81
  "@playwright/test": "1.41.2",
@@ -94,8 +96,8 @@
94
96
  "typescript": "5.4.0-dev.20240206",
95
97
  "vite": "5.0.12",
96
98
  "vue": "3.4.15",
97
- "@serwist/constants": "9.0.0-preview.2",
98
- "@serwist/sw": "9.0.0-preview.2"
99
+ "@serwist/constants": "9.0.0-preview.4",
100
+ "@serwist/sw": "9.0.0-preview.4"
99
101
  },
100
102
  "peerDependencies": {
101
103
  "@sveltejs/kit": "^1.0.0 || ^2.0.0",
@@ -106,7 +108,7 @@
106
108
  "typescript": ">=5.0.0",
107
109
  "vite": "^5.0.0",
108
110
  "vue": "^3.0.0",
109
- "@serwist/sw": "9.0.0-preview.2"
111
+ "@serwist/sw": "9.0.0-preview.4"
110
112
  },
111
113
  "peerDependenciesMeta": {
112
114
  "@serwist/sw": {
@@ -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
7
  urlPattern: /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i,
6
- handler: "CacheFirst",
7
- options: {
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
19
  urlPattern: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
17
- handler: "StaleWhileRevalidate",
18
- options: {
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
31
  urlPattern: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
28
- handler: "StaleWhileRevalidate",
29
- options: {
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
43
  urlPattern: /\.(?:js)$/i,
39
- handler: "StaleWhileRevalidate",
40
- options: {
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
55
  urlPattern: /\.(?:css|less)$/i,
50
- handler: "StaleWhileRevalidate",
51
- options: {
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
67
  urlPattern: /\.(?:json|xml|csv)$/i,
61
- handler: "NetworkFirst",
62
- options: {
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
79
  urlPattern: /\/api\/.*$/i,
72
- handler: "NetworkFirst",
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
93
  urlPattern: /.*/i,
85
- handler: "NetworkFirst",
86
- options: {
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[];