@serwist/vite 9.5.7 → 9.5.9

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.
Files changed (52) hide show
  1. package/dist/chunks/schema-CF26pDQI.js +77 -0
  2. package/dist/chunks/schema-CF26pDQI.js.map +1 -0
  3. package/dist/index.d.mts +228 -0
  4. package/dist/index.d.mts.map +1 -0
  5. package/dist/index.mjs +393 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/dist/index.schema.d.mts +126 -0
  8. package/dist/index.schema.d.mts.map +1 -0
  9. package/dist/index.schema.mjs +2 -0
  10. package/dist/index.worker.d.mts +13 -0
  11. package/dist/index.worker.d.mts.map +1 -0
  12. package/dist/index.worker.mjs +108 -0
  13. package/dist/index.worker.mjs.map +1 -0
  14. package/package.json +30 -26
  15. package/dist/chunks/schema.js +0 -80
  16. package/dist/index.d.ts +0 -19
  17. package/dist/index.d.ts.map +0 -1
  18. package/dist/index.js +0 -400
  19. package/dist/index.schema.d.ts +0 -3
  20. package/dist/index.schema.d.ts.map +0 -1
  21. package/dist/index.schema.js +0 -3
  22. package/dist/index.worker.d.ts +0 -9
  23. package/dist/index.worker.d.ts.map +0 -1
  24. package/dist/index.worker.js +0 -118
  25. package/dist/lib/api.d.ts +0 -4
  26. package/dist/lib/api.d.ts.map +0 -1
  27. package/dist/lib/constants.d.ts +0 -3
  28. package/dist/lib/constants.d.ts.map +0 -1
  29. package/dist/lib/context.d.ts +0 -33
  30. package/dist/lib/context.d.ts.map +0 -1
  31. package/dist/lib/log.d.ts +0 -4
  32. package/dist/lib/log.d.ts.map +0 -1
  33. package/dist/lib/modules.d.ts +0 -10
  34. package/dist/lib/modules.d.ts.map +0 -1
  35. package/dist/lib/options.d.ts +0 -4
  36. package/dist/lib/options.d.ts.map +0 -1
  37. package/dist/lib/schema.d.ts +0 -122
  38. package/dist/lib/schema.d.ts.map +0 -1
  39. package/dist/lib/types.d.ts +0 -130
  40. package/dist/lib/types.d.ts.map +0 -1
  41. package/dist/lib/utils.d.ts +0 -24
  42. package/dist/lib/utils.d.ts.map +0 -1
  43. package/dist/lib/validator.d.ts +0 -3
  44. package/dist/lib/validator.d.ts.map +0 -1
  45. package/dist/plugins/build.d.ts +0 -12
  46. package/dist/plugins/build.d.ts.map +0 -1
  47. package/dist/plugins/dev.d.ts +0 -12
  48. package/dist/plugins/dev.d.ts.map +0 -1
  49. package/dist/plugins/main.d.ts +0 -12
  50. package/dist/plugins/main.d.ts.map +0 -1
  51. package/src/rollup.js +0 -23
  52. /package/{typings.d.ts → typings.d.mts} +0 -0
@@ -0,0 +1,108 @@
1
+ import { CacheFirst, ExpirationPlugin, NetworkFirst, NetworkOnly, StaleWhileRevalidate } from "serwist";
2
+ //#region src/index.worker.ts
3
+ /**
4
+ * The default, recommended list of caching strategies for applications
5
+ * built with Vite.
6
+ *
7
+ * @see https://serwist.pages.dev/docs/vite/worker-exports#default-cache
8
+ */
9
+ const defaultCache = import.meta.env.DEV ? [{
10
+ matcher: /.*/i,
11
+ handler: new NetworkOnly()
12
+ }] : [
13
+ {
14
+ matcher: /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i,
15
+ handler: new CacheFirst({
16
+ cacheName: "google-fonts",
17
+ plugins: [new ExpirationPlugin({
18
+ maxEntries: 4,
19
+ maxAgeSeconds: 365 * 24 * 60 * 60,
20
+ maxAgeFrom: "last-used"
21
+ })]
22
+ })
23
+ },
24
+ {
25
+ matcher: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
26
+ handler: new StaleWhileRevalidate({
27
+ cacheName: "static-font-assets",
28
+ plugins: [new ExpirationPlugin({
29
+ maxEntries: 4,
30
+ maxAgeSeconds: 10080 * 60,
31
+ maxAgeFrom: "last-used"
32
+ })]
33
+ })
34
+ },
35
+ {
36
+ matcher: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
37
+ handler: new StaleWhileRevalidate({
38
+ cacheName: "static-image-assets",
39
+ plugins: [new ExpirationPlugin({
40
+ maxEntries: 64,
41
+ maxAgeSeconds: 1440 * 60,
42
+ maxAgeFrom: "last-used"
43
+ })]
44
+ })
45
+ },
46
+ {
47
+ matcher: /\.(?:js)$/i,
48
+ handler: new StaleWhileRevalidate({
49
+ cacheName: "static-js-assets",
50
+ plugins: [new ExpirationPlugin({
51
+ maxEntries: 32,
52
+ maxAgeSeconds: 1440 * 60,
53
+ maxAgeFrom: "last-used"
54
+ })]
55
+ })
56
+ },
57
+ {
58
+ matcher: /\.(?:css|less)$/i,
59
+ handler: new StaleWhileRevalidate({
60
+ cacheName: "static-style-assets",
61
+ plugins: [new ExpirationPlugin({
62
+ maxEntries: 32,
63
+ maxAgeSeconds: 1440 * 60,
64
+ maxAgeFrom: "last-used"
65
+ })]
66
+ })
67
+ },
68
+ {
69
+ matcher: /\.(?:json|xml|csv)$/i,
70
+ handler: new NetworkFirst({
71
+ cacheName: "static-data-assets",
72
+ plugins: [new ExpirationPlugin({
73
+ maxEntries: 32,
74
+ maxAgeSeconds: 1440 * 60,
75
+ maxAgeFrom: "last-used"
76
+ })]
77
+ })
78
+ },
79
+ {
80
+ matcher: /\/api\/.*$/i,
81
+ method: "GET",
82
+ handler: new NetworkFirst({
83
+ cacheName: "apis",
84
+ plugins: [new ExpirationPlugin({
85
+ maxEntries: 16,
86
+ maxAgeSeconds: 1440 * 60,
87
+ maxAgeFrom: "last-used"
88
+ })],
89
+ networkTimeoutSeconds: 10
90
+ })
91
+ },
92
+ {
93
+ matcher: /.*/i,
94
+ handler: new NetworkFirst({
95
+ cacheName: "others",
96
+ plugins: [new ExpirationPlugin({
97
+ maxEntries: 32,
98
+ maxAgeSeconds: 1440 * 60,
99
+ maxAgeFrom: "last-used"
100
+ })],
101
+ networkTimeoutSeconds: 10
102
+ })
103
+ }
104
+ ];
105
+ //#endregion
106
+ export { defaultCache };
107
+
108
+ //# sourceMappingURL=index.worker.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.worker.mjs","names":[],"sources":["../src/index.worker.ts"],"sourcesContent":["import type { RuntimeCaching } from \"serwist\";\nimport { CacheFirst, ExpirationPlugin, NetworkFirst, NetworkOnly, StaleWhileRevalidate } from \"serwist\";\n\n/**\n * The default, recommended list of caching strategies for applications\n * built with Vite.\n *\n * @see https://serwist.pages.dev/docs/vite/worker-exports#default-cache\n */\nexport const defaultCache: RuntimeCaching[] = import.meta.env.DEV\n ? [\n {\n matcher: /.*/i,\n handler: new NetworkOnly(),\n },\n ]\n : [\n {\n matcher: /^https:\\/\\/fonts\\.(?:googleapis|gstatic)\\.com\\/.*/i,\n handler: new CacheFirst({\n cacheName: \"google-fonts\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 4,\n maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,\n handler: new StaleWhileRevalidate({\n cacheName: \"static-font-assets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 4,\n maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,\n handler: new StaleWhileRevalidate({\n cacheName: \"static-image-assets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 64,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\.(?:js)$/i,\n handler: new StaleWhileRevalidate({\n cacheName: \"static-js-assets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\.(?:css|less)$/i,\n handler: new StaleWhileRevalidate({\n cacheName: \"static-style-assets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\.(?:json|xml|csv)$/i,\n handler: new NetworkFirst({\n cacheName: \"static-data-assets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\/api\\/.*$/i,\n method: \"GET\",\n handler: new NetworkFirst({\n cacheName: \"apis\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 16,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n ],\n networkTimeoutSeconds: 10, // fallback to cache if API does not response within 10 seconds\n }),\n },\n {\n matcher: /.*/i,\n handler: new NetworkFirst({\n cacheName: \"others\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n ],\n networkTimeoutSeconds: 10,\n }),\n },\n ];\n"],"mappings":";;;;;;;;AASA,MAAa,eAAiC,OAAO,KAAK,IAAI,MAC1D,CACE;CACE,SAAS;CACT,SAAS,IAAI,aAAa;CAC3B,CACF,GACD;CACE;EACE,SAAS;EACT,SAAS,IAAI,WAAW;GACtB,WAAW;GACX,SAAS,CACP,IAAI,iBAAiB;IACnB,YAAY;IACZ,eAAe,MAAM,KAAK,KAAK;IAC/B,YAAY;IACb,CAAC,CACH;GACF,CAAC;EACH;CACD;EACE,SAAS;EACT,SAAS,IAAI,qBAAqB;GAChC,WAAW;GACX,SAAS,CACP,IAAI,iBAAiB;IACnB,YAAY;IACZ,eAAe,QAAc;IAC7B,YAAY;IACb,CAAC,CACH;GACF,CAAC;EACH;CACD;EACE,SAAS;EACT,SAAS,IAAI,qBAAqB;GAChC,WAAW;GACX,SAAS,CACP,IAAI,iBAAiB;IACnB,YAAY;IACZ,eAAe,OAAU;IACzB,YAAY;IACb,CAAC,CACH;GACF,CAAC;EACH;CACD;EACE,SAAS;EACT,SAAS,IAAI,qBAAqB;GAChC,WAAW;GACX,SAAS,CACP,IAAI,iBAAiB;IACnB,YAAY;IACZ,eAAe,OAAU;IACzB,YAAY;IACb,CAAC,CACH;GACF,CAAC;EACH;CACD;EACE,SAAS;EACT,SAAS,IAAI,qBAAqB;GAChC,WAAW;GACX,SAAS,CACP,IAAI,iBAAiB;IACnB,YAAY;IACZ,eAAe,OAAU;IACzB,YAAY;IACb,CAAC,CACH;GACF,CAAC;EACH;CACD;EACE,SAAS;EACT,SAAS,IAAI,aAAa;GACxB,WAAW;GACX,SAAS,CACP,IAAI,iBAAiB;IACnB,YAAY;IACZ,eAAe,OAAU;IACzB,YAAY;IACb,CAAC,CACH;GACF,CAAC;EACH;CACD;EACE,SAAS;EACT,QAAQ;EACR,SAAS,IAAI,aAAa;GACxB,WAAW;GACX,SAAS,CACP,IAAI,iBAAiB;IACnB,YAAY;IACZ,eAAe,OAAU;IACzB,YAAY;IACb,CAAC,CACH;GACD,uBAAuB;GACxB,CAAC;EACH;CACD;EACE,SAAS;EACT,SAAS,IAAI,aAAa;GACxB,WAAW;GACX,SAAS,CACP,IAAI,iBAAiB;IACnB,YAAY;IACZ,eAAe,OAAU;IACzB,YAAY;IACb,CAAC,CACH;GACD,uBAAuB;GACxB,CAAC;EACH;CACF"}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@serwist/vite",
3
- "version": "9.5.7",
3
+ "version": "9.5.9",
4
4
  "type": "module",
5
5
  "description": "A module that integrates Serwist into your Vite application.",
6
6
  "files": [
7
7
  "src",
8
8
  "dist",
9
- "*.d.ts"
9
+ "*.d.mts"
10
10
  ],
11
11
  "keywords": [
12
12
  "react",
@@ -38,36 +38,36 @@
38
38
  "bugs": "https://github.com/serwist/serwist/issues",
39
39
  "homepage": "https://serwist.pages.dev",
40
40
  "sideEffects": false,
41
- "main": "./dist/index.js",
42
- "types": "./dist/index.d.ts",
41
+ "main": "./dist/index.mjs",
42
+ "types": "./dist/index.d.mts",
43
43
  "typesVersions": {
44
44
  "*": {
45
45
  "worker": [
46
- "./dist/index.worker.d.ts"
46
+ "./dist/index.worker.d.mts"
47
47
  ],
48
48
  "schema": [
49
- "./dist/index.schema.d.ts"
49
+ "./dist/index.schema.d.mts"
50
50
  ],
51
51
  "typings": [
52
- "./typings.d.ts"
52
+ "./typings.d.mts"
53
53
  ]
54
54
  }
55
55
  },
56
56
  "exports": {
57
57
  ".": {
58
- "types": "./dist/index.d.ts",
59
- "default": "./dist/index.js"
58
+ "types": "./dist/index.d.mts",
59
+ "default": "./dist/index.mjs"
60
60
  },
61
61
  "./worker": {
62
- "types": "./dist/index.worker.d.ts",
63
- "default": "./dist/index.worker.js"
62
+ "types": "./dist/index.worker.d.mts",
63
+ "default": "./dist/index.worker.mjs"
64
64
  },
65
65
  "./schema": {
66
- "types": "./dist/index.schema.d.ts",
67
- "default": "./dist/index.schema.js"
66
+ "types": "./dist/index.schema.d.mts",
67
+ "default": "./dist/index.schema.mjs"
68
68
  },
69
69
  "./typings": {
70
- "types": "./typings.d.ts"
70
+ "types": "./typings.d.mts"
71
71
  },
72
72
  "./package.json": "./package.json"
73
73
  },
@@ -75,31 +75,35 @@
75
75
  "glob": "10.5.0",
76
76
  "kolorist": "1.8.0",
77
77
  "zod": "4.3.6",
78
- "@serwist/build": "9.5.7",
79
- "@serwist/utils": "9.5.7",
80
- "serwist": "9.5.7"
78
+ "@serwist/build": "9.5.9",
79
+ "@serwist/utils": "9.5.9",
80
+ "serwist": "9.5.9"
81
81
  },
82
82
  "devDependencies": {
83
- "@types/node": "25.5.0",
84
- "rollup": "4.59.0",
85
- "typescript": "5.9.3",
86
- "vite": "8.0.0",
87
- "@serwist/configs": "9.5.7",
88
- "serwist": "9.5.7",
89
- "@serwist/window": "9.5.7"
83
+ "@types/node": "25.6.0",
84
+ "rollup": "4.60.2",
85
+ "tsdown": "0.21.10",
86
+ "typescript": "6.0.3",
87
+ "vite": "8.0.10",
88
+ "@serwist/window": "9.5.9",
89
+ "serwist": "9.5.9"
90
90
  },
91
91
  "peerDependencies": {
92
+ "rollup": ">=4.0.0",
92
93
  "typescript": ">=5.0.0",
93
94
  "vite": ">=5.0.0"
94
95
  },
95
96
  "peerDependenciesMeta": {
97
+ "rollup": {
98
+ "optional": true
99
+ },
96
100
  "typescript": {
97
101
  "optional": true
98
102
  }
99
103
  },
100
104
  "scripts": {
101
- "build": "rimraf dist && NODE_ENV=production rollup --config rollup.config.js",
102
- "dev": "rollup --config rollup.config.js --watch",
105
+ "build": "rimraf dist && NODE_ENV=production tsdown",
106
+ "dev": "tsdown --watch",
103
107
  "lint": "biome lint ./src",
104
108
  "typecheck": "tsc"
105
109
  }
@@ -1,80 +0,0 @@
1
- import { fn, asyncFn, requiredGlobDirectoryPartial, requiredSwDestPartial, injectPartial, globPartial, basePartial } from '@serwist/build/schema';
2
- import { z } from 'zod';
3
-
4
- const hooks = z.object({
5
- beforeBuildServiceWorker: z.union([
6
- fn({
7
- input: [
8
- z.any()
9
- ],
10
- output: z.void()
11
- }),
12
- asyncFn({
13
- input: [
14
- z.any()
15
- ],
16
- output: z.void()
17
- })
18
- ]).optional(),
19
- closeBundleOrder: z.union([
20
- z.literal("pre"),
21
- z.literal("post"),
22
- z.null()
23
- ]).optional(),
24
- configureOptions: z.union([
25
- fn({
26
- input: [
27
- z.any(),
28
- z.any()
29
- ],
30
- output: z.void()
31
- }),
32
- asyncFn({
33
- input: [
34
- z.any(),
35
- z.any()
36
- ],
37
- output: z.void()
38
- })
39
- ]).optional()
40
- });
41
- const devOptions = z.object({
42
- bundle: z.boolean().default(true),
43
- minify: z.union([
44
- z.boolean(),
45
- z.literal("terser"),
46
- z.literal("esbuild")
47
- ]).default(false)
48
- });
49
- const injectManifestPartial = z.object({
50
- mode: z.union([
51
- z.literal("development"),
52
- z.literal("production")
53
- ]),
54
- type: z.union([
55
- z.literal("classic"),
56
- z.literal("module")
57
- ]).default("classic"),
58
- scope: z.string(),
59
- base: z.string(),
60
- disable: z.boolean().default(false),
61
- integration: hooks.default({}),
62
- swUrl: z.string().default("/sw.js"),
63
- plugins: z.array(z.any()).default([]),
64
- rollupFormat: z.union([
65
- z.literal("es"),
66
- z.literal("iife")
67
- ]).default("es"),
68
- rollupOptions: z.record(z.string(), z.any()).default({}),
69
- devOptions: devOptions.prefault({})
70
- });
71
- const injectManifestOptions = z.strictObject({
72
- ...basePartial.shape,
73
- ...globPartial.shape,
74
- ...injectPartial.shape,
75
- ...requiredSwDestPartial.shape,
76
- ...requiredGlobDirectoryPartial.shape,
77
- ...injectManifestPartial.shape
78
- });
79
-
80
- export { devOptions, hooks, injectManifestOptions, injectManifestPartial };
package/dist/index.d.ts DELETED
@@ -1,19 +0,0 @@
1
- import type { Plugin } from "vite";
2
- import { createApi } from "./lib/api.js";
3
- import { createContext } from "./lib/context.js";
4
- import type { DevOptions, ExtendManifestEntriesHook, Hooks, PluginOptions, PluginOptionsComplete, SerwistViteApi } from "./lib/types.js";
5
- import { resolveEntry, toFs } from "./lib/utils.js";
6
- import { validateInjectManifestOptions } from "./lib/validator.js";
7
- import { buildPlugin } from "./plugins/build.js";
8
- import { devPlugin } from "./plugins/dev.js";
9
- import { mainPlugin } from "./plugins/main.js";
10
- /**
11
- * Integrates Serwist into your Vite app.
12
- * @param userOptions
13
- * @returns
14
- */
15
- export declare const serwist: (userOptions: PluginOptions) => Plugin[];
16
- export { buildPlugin as build, createApi, createContext, devPlugin as dev, mainPlugin as main, resolveEntry, toFs, validateInjectManifestOptions };
17
- export type { SerwistViteContext } from "./lib/context.js";
18
- export type { PluginOptions, PluginOptionsComplete, Hooks, ExtendManifestEntriesHook, DevOptions, SerwistViteApi };
19
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,yBAAyB,EAAE,KAAK,EAAE,aAAa,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACzI,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,aAAa,aAAa,KAAG,MAAM,EAI1D,CAAC;AAGF,OAAO,EAAE,WAAW,IAAI,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,IAAI,GAAG,EAAE,UAAU,IAAI,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,6BAA6B,EAAE,CAAC;AACnJ,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,YAAY,EAAE,aAAa,EAAE,qBAAqB,EAAE,KAAK,EAAE,yBAAyB,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC"}