@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.
- package/dist/index.worker.d.ts +10 -2
- package/dist/index.worker.d.ts.map +1 -1
- package/dist/index.worker.js +67 -56
- package/dist/main.js +1 -1
- package/package.json +8 -6
- package/src/index.worker.ts +68 -58
package/dist/index.worker.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare const defaultCache:
|
|
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":"
|
|
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"}
|
package/dist/index.worker.js
CHANGED
|
@@ -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:
|
|
5
|
-
options: {
|
|
7
|
+
handler: new CacheFirst({
|
|
6
8
|
cacheName: "google-fonts",
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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:
|
|
16
|
-
options: {
|
|
19
|
+
handler: new StaleWhileRevalidate({
|
|
17
20
|
cacheName: "static-font-assets",
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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:
|
|
27
|
-
options: {
|
|
31
|
+
handler: new StaleWhileRevalidate({
|
|
28
32
|
cacheName: "static-image-assets",
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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:
|
|
38
|
-
options: {
|
|
43
|
+
handler: new StaleWhileRevalidate({
|
|
39
44
|
cacheName: "static-js-assets",
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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:
|
|
49
|
-
options: {
|
|
55
|
+
handler: new StaleWhileRevalidate({
|
|
50
56
|
cacheName: "static-style-assets",
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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:
|
|
60
|
-
options: {
|
|
67
|
+
handler: new NetworkFirst({
|
|
61
68
|
cacheName: "static-data-assets",
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
80
|
+
handler: new NetworkFirst({
|
|
73
81
|
cacheName: "apis",
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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:
|
|
84
|
-
options: {
|
|
93
|
+
handler: new NetworkFirst({
|
|
85
94
|
cacheName: "others",
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
76
|
-
"@serwist/
|
|
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.
|
|
98
|
-
"@serwist/sw": "9.0.0-preview.
|
|
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.
|
|
111
|
+
"@serwist/sw": "9.0.0-preview.4"
|
|
110
112
|
},
|
|
111
113
|
"peerDependenciesMeta": {
|
|
112
114
|
"@serwist/sw": {
|
package/src/index.worker.ts
CHANGED
|
@@ -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
|
|
5
|
+
export const defaultCache = [
|
|
4
6
|
{
|
|
5
7
|
urlPattern: /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i,
|
|
6
|
-
handler:
|
|
7
|
-
options: {
|
|
8
|
+
handler: new CacheFirst({
|
|
8
9
|
cacheName: "google-fonts",
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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:
|
|
18
|
-
options: {
|
|
20
|
+
handler: new StaleWhileRevalidate({
|
|
19
21
|
cacheName: "static-font-assets",
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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:
|
|
29
|
-
options: {
|
|
32
|
+
handler: new StaleWhileRevalidate({
|
|
30
33
|
cacheName: "static-image-assets",
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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:
|
|
40
|
-
options: {
|
|
44
|
+
handler: new StaleWhileRevalidate({
|
|
41
45
|
cacheName: "static-js-assets",
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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:
|
|
51
|
-
options: {
|
|
56
|
+
handler: new StaleWhileRevalidate({
|
|
52
57
|
cacheName: "static-style-assets",
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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:
|
|
62
|
-
options: {
|
|
68
|
+
handler: new NetworkFirst({
|
|
63
69
|
cacheName: "static-data-assets",
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
81
|
+
handler: new NetworkFirst({
|
|
75
82
|
cacheName: "apis",
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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:
|
|
86
|
-
options: {
|
|
94
|
+
handler: new NetworkFirst({
|
|
87
95
|
cacheName: "others",
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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[];
|