@serwist/vite 9.0.0-preview.2 → 9.0.0-preview.21
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/chunks/schema.js +56 -0
- package/dist/index.d.ts +8 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +360 -11
- package/dist/index.schema.d.ts +3 -0
- package/dist/index.schema.d.ts.map +1 -0
- package/dist/index.schema.js +3 -0
- package/dist/index.worker.d.ts +6 -0
- package/dist/index.worker.d.ts.map +1 -1
- package/dist/index.worker.js +84 -65
- package/dist/lib/api.d.ts.map +1 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/{context.d.ts → lib/context.d.ts} +3 -3
- package/dist/lib/context.d.ts.map +1 -0
- package/dist/lib/log.d.ts.map +1 -0
- package/dist/{modules.d.ts → lib/modules.d.ts} +1 -1
- package/dist/lib/modules.d.ts.map +1 -0
- package/dist/lib/options.d.ts +4 -0
- package/dist/lib/options.d.ts.map +1 -0
- package/dist/lib/schema.d.ts +359 -0
- package/dist/lib/schema.d.ts.map +1 -0
- package/dist/lib/types.d.ts +127 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/validator.d.ts +3 -0
- package/dist/lib/validator.d.ts.map +1 -0
- package/dist/plugins/build.d.ts +2 -2
- package/dist/plugins/build.d.ts.map +1 -1
- package/dist/plugins/dev.d.ts +2 -2
- package/dist/plugins/dev.d.ts.map +1 -1
- package/dist/plugins/main.d.ts +2 -2
- package/dist/plugins/main.d.ts.map +1 -1
- package/package.json +22 -62
- package/src/index.schema.ts +3 -0
- package/src/index.ts +8 -7
- package/src/index.worker.ts +111 -85
- package/src/{context.ts → lib/context.ts} +3 -3
- package/src/{log.ts → lib/log.ts} +1 -1
- package/src/{modules.ts → lib/modules.ts} +5 -6
- package/src/lib/options.ts +76 -0
- package/src/lib/schema.ts +35 -0
- package/src/lib/types.ts +163 -0
- package/src/lib/validator.ts +10 -0
- package/src/plugins/build.ts +2 -2
- package/src/plugins/dev.ts +3 -3
- package/src/plugins/main.ts +5 -5
- package/src/rollup.js +3 -24
- package/dist/api.d.ts.map +0 -1
- package/dist/assets.d.ts +0 -4
- package/dist/assets.d.ts.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/context.d.ts.map +0 -1
- package/dist/integration/svelte/build.d.ts +0 -5
- package/dist/integration/svelte/build.d.ts.map +0 -1
- package/dist/integration/svelte/config.d.ts +0 -9
- package/dist/integration/svelte/config.d.ts.map +0 -1
- package/dist/integration/svelte/index.d.ts +0 -10
- package/dist/integration/svelte/index.d.ts.map +0 -1
- package/dist/integration/svelte/index.js +0 -145
- package/dist/integration/svelte/types.d.ts +0 -24
- package/dist/integration/svelte/types.d.ts.map +0 -1
- package/dist/log.d.ts.map +0 -1
- package/dist/main.js +0 -470
- package/dist/modules.d.ts.map +0 -1
- package/dist/options.d.ts +0 -4
- package/dist/options.d.ts.map +0 -1
- package/dist/types.d.ts +0 -191
- package/dist/types.d.ts.map +0 -1
- package/dist/utils-types.d.ts +0 -2
- package/dist/utils-types.d.ts.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/src/assets.ts +0 -76
- package/src/integration/svelte/build.ts +0 -21
- package/src/integration/svelte/config.ts +0 -141
- package/src/integration/svelte/index.ts +0 -27
- package/src/integration/svelte/types.ts +0 -26
- package/src/options.ts +0 -90
- package/src/types.ts +0 -207
- package/src/utils-types.ts +0 -1
- /package/dist/{api.d.ts → lib/api.d.ts} +0 -0
- /package/dist/{constants.d.ts → lib/constants.d.ts} +0 -0
- /package/dist/{log.d.ts → lib/log.d.ts} +0 -0
- /package/dist/{utils.d.ts → lib/utils.d.ts} +0 -0
- /package/src/{api.ts → lib/api.ts} +0 -0
- /package/src/{constants.ts → lib/constants.ts} +0 -0
- /package/src/{utils.ts → lib/utils.ts} +0 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { BasePartial, BaseResolved, GlobPartial, GlobResolved, InjectPartial as BaseInjectPartial, InjectResolved as BaseInjectResolved, ManifestEntry, RequiredGlobDirectoryPartial, RequiredGlobDirectoryResolved, RequiredSwDestPartial, RequiredSwDestResolved } from "@serwist/build";
|
|
2
|
+
import type { Require } from "@serwist/utils";
|
|
3
|
+
import type { RollupOptions } from "rollup";
|
|
4
|
+
import type { BuildOptions, Plugin, ResolvedConfig } from "vite";
|
|
5
|
+
export interface InjectPartial {
|
|
6
|
+
/**
|
|
7
|
+
* The mode in which Serwist should be built.
|
|
8
|
+
*
|
|
9
|
+
* @default
|
|
10
|
+
* process.env.NODE_ENV // or "production" if undefined
|
|
11
|
+
*/
|
|
12
|
+
mode?: "development" | "production";
|
|
13
|
+
/**
|
|
14
|
+
* The service worker type.
|
|
15
|
+
*
|
|
16
|
+
* @default "classic"
|
|
17
|
+
*/
|
|
18
|
+
type?: WorkerType;
|
|
19
|
+
/**
|
|
20
|
+
* The scope with which Serwist should register the service worker.
|
|
21
|
+
*
|
|
22
|
+
* @default viteOptions.base
|
|
23
|
+
*/
|
|
24
|
+
scope?: string;
|
|
25
|
+
/**
|
|
26
|
+
* The base from which Serwist resolves URLs.
|
|
27
|
+
*
|
|
28
|
+
* @default viteOptions.base
|
|
29
|
+
*/
|
|
30
|
+
base?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Whether Serwist should be disabled.
|
|
33
|
+
*
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
36
|
+
disable?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Hooks of the build lifecycle.
|
|
39
|
+
*/
|
|
40
|
+
integration?: Hooks;
|
|
41
|
+
/**
|
|
42
|
+
* The URL to the service worker.
|
|
43
|
+
*
|
|
44
|
+
* @default "/sw.js"
|
|
45
|
+
*/
|
|
46
|
+
swUrl?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Plugins used to build your service worker.
|
|
49
|
+
*/
|
|
50
|
+
plugins?: Plugin[];
|
|
51
|
+
/**
|
|
52
|
+
* The format used to build the service worker.
|
|
53
|
+
*
|
|
54
|
+
* @default "es"
|
|
55
|
+
*/
|
|
56
|
+
rollupFormat?: "es" | "iife";
|
|
57
|
+
/**
|
|
58
|
+
* Custom Rollup options used to build the service worker.
|
|
59
|
+
*/
|
|
60
|
+
rollupOptions?: Omit<RollupOptions, "plugins" | "output">;
|
|
61
|
+
/**
|
|
62
|
+
* Development-specific options.
|
|
63
|
+
*/
|
|
64
|
+
devOptions?: DevOptions;
|
|
65
|
+
}
|
|
66
|
+
export interface InjectResolved extends Require<InjectPartial, "mode" | "type" | "scope" | "base" | "disable" | "swUrl" | "rollupFormat"> {
|
|
67
|
+
devOptions: Required<DevOptions>;
|
|
68
|
+
}
|
|
69
|
+
export interface InjectManifestOptions extends Omit<BasePartial, "disablePrecacheManifest">, GlobPartial, BaseInjectPartial, RequiredSwDestPartial, RequiredGlobDirectoryPartial, InjectPartial {
|
|
70
|
+
}
|
|
71
|
+
export interface InjectManifestOptionsComplete extends BaseResolved, GlobResolved, BaseInjectResolved, RequiredSwDestResolved, RequiredGlobDirectoryResolved, InjectResolved {
|
|
72
|
+
}
|
|
73
|
+
export interface Hooks {
|
|
74
|
+
beforeBuildServiceWorker?: (options: PluginOptionsComplete) => void | Promise<void>;
|
|
75
|
+
closeBundleOrder?: "pre" | "post" | null;
|
|
76
|
+
configureOptions?: (viteOptions: ResolvedConfig, options: PluginOptions) => void | Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
export interface DevOptions {
|
|
79
|
+
/**
|
|
80
|
+
* Whether the service worker should be bundled in development mode.
|
|
81
|
+
*
|
|
82
|
+
* Many browsers still [do not support ES Modules in service workers](https://caniuse.com/mdn-api_serviceworker_ecmascript_modules). However, in development
|
|
83
|
+
* mode, certain frameworks, such as SvelteKit, do not bundle the service worker. As a result, trying to register that service worker on browsers lacking
|
|
84
|
+
* support, such as Firefox or Safari, will fail, but doing so on browsers not lacking support will not fail. This option is provided to prevent that from
|
|
85
|
+
* happening. What the plugin does is intercepting any request to the service worker (requests for `swUrl`) and returning a bundled one.
|
|
86
|
+
*
|
|
87
|
+
* @default true
|
|
88
|
+
*/
|
|
89
|
+
bundle?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Whether the service worker should be minified in development mode.
|
|
92
|
+
*
|
|
93
|
+
* @default false
|
|
94
|
+
*/
|
|
95
|
+
minify?: BuildOptions["minify"];
|
|
96
|
+
}
|
|
97
|
+
export interface PluginOptions extends InjectManifestOptions {
|
|
98
|
+
}
|
|
99
|
+
export interface PluginOptionsComplete extends InjectResolved {
|
|
100
|
+
injectManifest: Omit<InjectManifestOptionsComplete, keyof InjectResolved>;
|
|
101
|
+
}
|
|
102
|
+
export interface ShareTargetFiles {
|
|
103
|
+
name: string;
|
|
104
|
+
accept: string | string[];
|
|
105
|
+
}
|
|
106
|
+
type Nothing = {};
|
|
107
|
+
/**
|
|
108
|
+
* type StringLiteralUnion<'maskable'> = 'maskable' | string
|
|
109
|
+
* This has auto completion whereas `'maskable' | string` doesn't
|
|
110
|
+
* Adapted from https://github.com/microsoft/TypeScript/issues/29729
|
|
111
|
+
*/
|
|
112
|
+
export type StringLiteralUnion<T extends U, U = string> = T | (U & Nothing);
|
|
113
|
+
export interface SerwistViteApi {
|
|
114
|
+
/**
|
|
115
|
+
* Whether the plugin is disabled.
|
|
116
|
+
*/
|
|
117
|
+
disabled: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Extends the precache manifest.
|
|
120
|
+
* @param fn
|
|
121
|
+
*/
|
|
122
|
+
extendManifestEntries(fn: ExtendManifestEntriesHook): void;
|
|
123
|
+
generateSW(): Promise<void>;
|
|
124
|
+
}
|
|
125
|
+
export type ExtendManifestEntriesHook = (manifestEntries: (string | ManifestEntry)[]) => (string | ManifestEntry)[] | undefined;
|
|
126
|
+
export {};
|
|
127
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib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WAAW,cAAc;IAC7B;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,EAAE,yBAAyB,GAAG,IAAI,CAAC;IAI3D,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B;AAED,MAAM,MAAM,yBAAyB,GAAG,CAAC,eAAe,EAAE,CAAC,MAAM,GAAG,aAAa,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,aAAa,CAAC,EAAE,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,KAAK,QAAS,MAAM,WAEhC,CAAC;AAEF,eAAO,MAAM,eAAe,SAAU,MAAM,WAG3C,CAAC;AAEF,eAAO,MAAM,UAAU,QAAS,MAAM,4BAErC,CAAC;AAEF,eAAO,MAAM,aAAa,SAAU,MAAM,WAEzC,CAAC;AAIF;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,UAAW,MAAM,KAAG,MAAM,GAAG,IAqBrD,CAAC;AAIF;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI,QAAS,MAAM,WAI/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/lib/validator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAEhE,eAAO,MAAM,6BAA6B,UAAiB,OAAO,KAAG,QAAQ,6BAA6B,CAMzG,CAAC"}
|
package/dist/plugins/build.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
|
-
import type { SerwistViteContext } from "../context.js";
|
|
3
|
-
import type { SerwistViteApi } from "../types.js";
|
|
2
|
+
import type { SerwistViteContext } from "../lib/context.js";
|
|
3
|
+
import type { SerwistViteApi } from "../lib/types.js";
|
|
4
4
|
/**
|
|
5
5
|
* Internal build plugin used by `@serwist/vite`.
|
|
6
6
|
* @internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/plugins/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/plugins/build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,QAAS,kBAAkB,OAAO,cAAc,gBAkBvE,CAAC"}
|
package/dist/plugins/dev.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Plugin } from "vite";
|
|
2
|
-
import type { SerwistViteContext } from "../context.js";
|
|
3
|
-
import type { SerwistViteApi } from "../types.js";
|
|
2
|
+
import type { SerwistViteContext } from "../lib/context.js";
|
|
3
|
+
import type { SerwistViteApi } from "../lib/types.js";
|
|
4
4
|
/**
|
|
5
5
|
* Internal dev plugin used by `@serwist/vite`.
|
|
6
6
|
* @internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/plugins/dev.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,MAAM,EAAiB,MAAM,MAAM,CAAC;AAElD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/plugins/dev.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,MAAM,EAAiB,MAAM,MAAM,CAAC;AAElD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAStD;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,QAAS,kBAAkB,OAAO,cAAc,KAAG,MAsCxE,CAAC"}
|
package/dist/plugins/main.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
|
-
import type { SerwistViteContext } from "../context.js";
|
|
3
|
-
import type { SerwistViteApi } from "../types.js";
|
|
2
|
+
import type { SerwistViteContext } from "../lib/context.js";
|
|
3
|
+
import type { SerwistViteApi } from "../lib/types.js";
|
|
4
4
|
/**
|
|
5
5
|
* Internal plugin used by `@serwist/vite`.
|
|
6
6
|
* @internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/plugins/main.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,MAAM,CAAC;AAG/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/plugins/main.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,MAAM,CAAC;AAG/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,QAAS,kBAAkB,OAAO,cAAc,gBAgCtE,CAAC"}
|
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.21",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A module that integrates Serwist into your Vite application.",
|
|
6
6
|
"files": [
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
},
|
|
31
31
|
"author": "antfu <anthonyfu117@hotmail.com>, Serwist's Team",
|
|
32
32
|
"license": "MIT",
|
|
33
|
-
"repository": "serwist/serwist",
|
|
34
|
-
"bugs": "https://
|
|
33
|
+
"repository": "https://gitlab.com/serwist/serwist",
|
|
34
|
+
"bugs": "https://gitlab.com/serwist/serwist/issues",
|
|
35
35
|
"homepage": "https://serwist.pages.dev",
|
|
36
36
|
"sideEffects": false,
|
|
37
37
|
"main": "./dist/index.js",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"worker": [
|
|
45
45
|
"./dist/index.worker.d.ts"
|
|
46
46
|
],
|
|
47
|
-
"
|
|
48
|
-
"./dist/
|
|
47
|
+
"schema": [
|
|
48
|
+
"./dist/index.schema.d.ts"
|
|
49
49
|
]
|
|
50
50
|
}
|
|
51
51
|
},
|
|
@@ -62,76 +62,36 @@
|
|
|
62
62
|
"types": "./dist/index.worker.d.ts",
|
|
63
63
|
"default": "./dist/index.worker.js"
|
|
64
64
|
},
|
|
65
|
-
"./
|
|
66
|
-
"types": "./dist/
|
|
67
|
-
"default": "./dist/
|
|
65
|
+
"./schema": {
|
|
66
|
+
"types": "./dist/index.schema.d.ts",
|
|
67
|
+
"default": "./dist/index.schema.js"
|
|
68
68
|
},
|
|
69
69
|
"./package.json": "./package.json"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"@serwist/build": "9.0.0-preview.
|
|
76
|
-
"@serwist/
|
|
72
|
+
"glob": "10.3.10",
|
|
73
|
+
"kolorist": "1.8.0",
|
|
74
|
+
"zod": "3.22.4",
|
|
75
|
+
"@serwist/build": "9.0.0-preview.21",
|
|
76
|
+
"@serwist/sw": "9.0.0-preview.21",
|
|
77
|
+
"@serwist/window": "9.0.0-preview.21"
|
|
77
78
|
},
|
|
78
79
|
"devDependencies": {
|
|
79
|
-
"@
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"@
|
|
84
|
-
"@
|
|
85
|
-
"
|
|
86
|
-
"kolorist": "1.8.0",
|
|
87
|
-
"preact": "10.19.3",
|
|
88
|
-
"prompts": "2.4.2",
|
|
89
|
-
"publint": "0.2.7",
|
|
90
|
-
"react": "18.2.0",
|
|
91
|
-
"rollup": "4.9.6",
|
|
92
|
-
"solid-js": "1.8.14",
|
|
93
|
-
"svelte": "5.0.0-next.48",
|
|
94
|
-
"typescript": "5.4.0-dev.20240206",
|
|
95
|
-
"vite": "5.0.12",
|
|
96
|
-
"vue": "3.4.15",
|
|
97
|
-
"@serwist/constants": "9.0.0-preview.2",
|
|
98
|
-
"@serwist/sw": "9.0.0-preview.2"
|
|
80
|
+
"@types/node": "20.11.30",
|
|
81
|
+
"rollup": "4.13.0",
|
|
82
|
+
"typescript": "5.5.0-dev.20240323",
|
|
83
|
+
"vite": "5.2.4",
|
|
84
|
+
"@serwist/constants": "9.0.0-preview.21",
|
|
85
|
+
"@serwist/sw": "9.0.0-preview.21",
|
|
86
|
+
"@serwist/utils": "9.0.0-preview.21"
|
|
99
87
|
},
|
|
100
88
|
"peerDependencies": {
|
|
101
|
-
"@sveltejs/kit": "^1.0.0 || ^2.0.0",
|
|
102
|
-
"preact": "^10.0.0",
|
|
103
|
-
"react": "^18.0.0",
|
|
104
|
-
"solid-js": "^1.8.7",
|
|
105
|
-
"svelte": "^4.0.0 || ^5.0.0",
|
|
106
89
|
"typescript": ">=5.0.0",
|
|
107
|
-
"vite": "^5.0.0"
|
|
108
|
-
"vue": "^3.0.0",
|
|
109
|
-
"@serwist/sw": "9.0.0-preview.2"
|
|
90
|
+
"vite": "^5.0.0"
|
|
110
91
|
},
|
|
111
92
|
"peerDependenciesMeta": {
|
|
112
|
-
"@serwist/sw": {
|
|
113
|
-
"optional": true
|
|
114
|
-
},
|
|
115
|
-
"@sveltejs/kit": {
|
|
116
|
-
"optional": true
|
|
117
|
-
},
|
|
118
|
-
"preact": {
|
|
119
|
-
"optional": true
|
|
120
|
-
},
|
|
121
|
-
"react": {
|
|
122
|
-
"optional": true
|
|
123
|
-
},
|
|
124
|
-
"solid-js": {
|
|
125
|
-
"optional": true
|
|
126
|
-
},
|
|
127
|
-
"svelte": {
|
|
128
|
-
"optional": true
|
|
129
|
-
},
|
|
130
93
|
"typescript": {
|
|
131
94
|
"optional": true
|
|
132
|
-
},
|
|
133
|
-
"vue": {
|
|
134
|
-
"optional": true
|
|
135
95
|
}
|
|
136
96
|
},
|
|
137
97
|
"scripts": {
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
2
|
|
|
3
|
-
import { createApi } from "./api.js";
|
|
4
|
-
import { createContext } from "./context.js";
|
|
3
|
+
import { createApi } from "./lib/api.js";
|
|
4
|
+
import { createContext } from "./lib/context.js";
|
|
5
|
+
import type { DevOptions, ExtendManifestEntriesHook, Hooks, PluginOptions, PluginOptionsComplete, SerwistViteApi } from "./lib/types.js";
|
|
6
|
+
import { resolveEntry, toFs } from "./lib/utils.js";
|
|
7
|
+
import { validateInjectManifestOptions } from "./lib/validator.js";
|
|
5
8
|
import { buildPlugin } from "./plugins/build.js";
|
|
6
9
|
import { devPlugin } from "./plugins/dev.js";
|
|
7
10
|
import { mainPlugin } from "./plugins/main.js";
|
|
8
|
-
import type { PluginOptions } from "./types.js";
|
|
9
|
-
import { resolveEntry, toFs } from "./utils.js";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Integrates Serwist into your Vite app.
|
|
@@ -20,6 +21,6 @@ export const serwist = (userOptions: PluginOptions): Plugin[] => {
|
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
// This allows for customization.
|
|
23
|
-
export { buildPlugin as build, createApi, createContext, devPlugin as dev, mainPlugin as main, resolveEntry, toFs };
|
|
24
|
-
export type { SerwistViteContext } from "./context.js";
|
|
25
|
-
export
|
|
24
|
+
export { buildPlugin as build, createApi, createContext, devPlugin as dev, mainPlugin as main, resolveEntry, toFs, validateInjectManifestOptions };
|
|
25
|
+
export type { SerwistViteContext } from "./lib/context.js";
|
|
26
|
+
export type { PluginOptions, PluginOptionsComplete, Hooks, ExtendManifestEntriesHook, DevOptions, SerwistViteApi };
|
package/src/index.worker.ts
CHANGED
|
@@ -1,95 +1,121 @@
|
|
|
1
1
|
import type { RuntimeCaching } from "@serwist/sw";
|
|
2
|
+
import { ExpirationPlugin } from "@serwist/sw/plugins";
|
|
3
|
+
import { CacheFirst, NetworkFirst, StaleWhileRevalidate } from "@serwist/sw/strategies";
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
+
],
|
|
25
|
+
}),
|
|
12
26
|
},
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
+
],
|
|
38
|
+
}),
|
|
23
39
|
},
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
+
],
|
|
51
|
+
}),
|
|
34
52
|
},
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
+
],
|
|
64
|
+
}),
|
|
45
65
|
},
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
+
],
|
|
77
|
+
}),
|
|
56
78
|
},
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
+
],
|
|
90
|
+
}),
|
|
67
91
|
},
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
|
105
|
+
}),
|
|
79
106
|
},
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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,
|
|
119
|
+
}),
|
|
91
120
|
},
|
|
92
|
-
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
];
|
|
121
|
+
];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ResolvedConfig } from "vite";
|
|
2
2
|
|
|
3
|
-
import type { PluginOptions,
|
|
3
|
+
import type { PluginOptions, PluginOptionsComplete } from "./types.js";
|
|
4
4
|
|
|
5
|
-
export type SerwistViteFrameworks = "nuxt"
|
|
5
|
+
export type SerwistViteFrameworks = "nuxt";
|
|
6
6
|
|
|
7
7
|
export interface SerwistViteContext {
|
|
8
8
|
/**
|
|
@@ -21,7 +21,7 @@ export interface SerwistViteContext {
|
|
|
21
21
|
* Note: this is different from `userOptions` in that it has been parsed, whereas
|
|
22
22
|
* `userOptions` is the raw configuration that the user provides us.
|
|
23
23
|
*/
|
|
24
|
-
options:
|
|
24
|
+
options: PluginOptionsComplete;
|
|
25
25
|
useImportRegister: boolean;
|
|
26
26
|
/**
|
|
27
27
|
* Is the plugin running on dev?
|
|
@@ -2,7 +2,7 @@ import type { BuildResult } from "@serwist/build";
|
|
|
2
2
|
import { cyan, dim, green, yellow } from "kolorist";
|
|
3
3
|
import type { ResolvedConfig } from "vite";
|
|
4
4
|
|
|
5
|
-
import { version } from "
|
|
5
|
+
import { version } from "../../package.json";
|
|
6
6
|
|
|
7
7
|
export const logSerwistResult = (buildResult: Pick<BuildResult, "count" | "size" | "warnings">, viteOptions: ResolvedConfig) => {
|
|
8
8
|
const { logLevel = "info" } = viteOptions;
|
|
@@ -21,9 +21,8 @@ interface BuildResult extends SerwistBuild.GetManifestResult {
|
|
|
21
21
|
manifestString: string;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export const injectManifest = async (
|
|
25
|
-
const {
|
|
26
|
-
const options = await validateViteInjectManifestOptions(config);
|
|
24
|
+
export const injectManifest = async (options: SerwistBuild.GetManifestOptionsComplete): Promise<BuildResult> => {
|
|
25
|
+
const { getFileManifestEntries, stringify } = await loadSerwistBuild();
|
|
27
26
|
const { count, size, manifestEntries, warnings } = await getFileManifestEntries(options);
|
|
28
27
|
const manifestString = manifestEntries === undefined ? "undefined" : stringify(manifestEntries);
|
|
29
28
|
return {
|
|
@@ -36,7 +35,7 @@ export const injectManifest = async (config: SerwistBuild.ViteInjectManifestOpti
|
|
|
36
35
|
};
|
|
37
36
|
|
|
38
37
|
export const generateServiceWorker = async (ctx: SerwistViteContext) => {
|
|
39
|
-
const {
|
|
38
|
+
const { plugins, rollupOptions, rollupFormat } = ctx.options;
|
|
40
39
|
|
|
41
40
|
const parsedSwDest = path.parse(ctx.options.injectManifest.swDest);
|
|
42
41
|
|
|
@@ -50,7 +49,7 @@ export const generateServiceWorker = async (ctx: SerwistViteContext) => {
|
|
|
50
49
|
const isProduction = ctx.options.mode === "production";
|
|
51
50
|
const isDev = ctx.options.mode === "development";
|
|
52
51
|
|
|
53
|
-
if (
|
|
52
|
+
if (isDev && !ctx.options.devOptions.bundle) {
|
|
54
53
|
if (!injectManifestResult) {
|
|
55
54
|
throw new Error("injectManifest failed to generate results. This is likely a bug.");
|
|
56
55
|
}
|
|
@@ -152,7 +151,7 @@ export const generateServiceWorker = async (ctx: SerwistViteContext) => {
|
|
|
152
151
|
lib: {
|
|
153
152
|
entry: ctx.options.injectManifest.swSrc,
|
|
154
153
|
name: "app",
|
|
155
|
-
formats: [
|
|
154
|
+
formats: [rollupFormat],
|
|
156
155
|
},
|
|
157
156
|
rollupOptions: {
|
|
158
157
|
...rollupOptions,
|