@serwist/vite 9.0.0-preview.8 → 9.0.0
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 +77 -180
- 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 +8 -10
- package/dist/index.worker.d.ts.map +1 -1
- package/dist/index.worker.js +18 -11
- package/dist/lib/api.d.ts.map +1 -0
- package/dist/lib/constants.d.ts +3 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/{context.d.ts → lib/context.d.ts} +2 -2
- 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 +130 -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 +29 -65
- package/src/index.schema.ts +3 -0
- package/src/index.ts +8 -7
- package/src/index.worker.ts +111 -96
- package/src/lib/constants.ts +2 -0
- package/src/{context.ts → lib/context.ts} +2 -2
- package/src/{log.ts → lib/log.ts} +1 -1
- package/src/{modules.ts → lib/modules.ts} +4 -5
- 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 +3 -3
- package/src/plugins/dev.ts +3 -3
- package/src/plugins/main.ts +15 -9
- package/src/rollup.js +4 -5
- 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 +0 -3
- package/dist/constants.d.ts.map +0 -1
- package/dist/context.d.ts.map +0 -1
- package/dist/index.browser.d.ts +0 -2
- package/dist/index.browser.d.ts.map +0 -1
- package/dist/index.browser.js +0 -13
- package/dist/log.d.ts.map +0 -1
- 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/constants.ts +0 -2
- package/src/index.browser.ts +0 -8
- package/src/options.ts +0 -90
- package/src/types.ts +0 -207
- package/src/utils-types.ts +0 -1
- package/src/virtual.d.ts +0 -5
- /package/dist/{api.d.ts → lib/api.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/{utils.ts → lib/utils.ts} +0 -0
package/src/options.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import process from "node:process";
|
|
3
|
-
|
|
4
|
-
import type { ResolvedConfig } from "vite";
|
|
5
|
-
|
|
6
|
-
import { configureStaticAssets } from "./assets.js";
|
|
7
|
-
import { loadSerwistBuild } from "./modules.js";
|
|
8
|
-
import type { PluginOptions, ResolvedPluginOptions } from "./types.js";
|
|
9
|
-
import { resolveBasePath, slash } from "./utils.js";
|
|
10
|
-
|
|
11
|
-
export const resolveOptions = async (options: PluginOptions, viteConfig: ResolvedConfig): Promise<ResolvedPluginOptions> => {
|
|
12
|
-
const {
|
|
13
|
-
type = "classic",
|
|
14
|
-
mode = process.env.NODE_ENV === "production" || process.env.NODE_ENV === "development" ? process.env.NODE_ENV : "production",
|
|
15
|
-
injectRegister = "auto",
|
|
16
|
-
registerType = "prompt",
|
|
17
|
-
minify = true,
|
|
18
|
-
base = viteConfig.base,
|
|
19
|
-
scope: _scope,
|
|
20
|
-
swUrl = "/sw.js",
|
|
21
|
-
includeAssets = undefined,
|
|
22
|
-
useCredentials = false,
|
|
23
|
-
disable = false,
|
|
24
|
-
integration = {},
|
|
25
|
-
buildBase,
|
|
26
|
-
devOptions,
|
|
27
|
-
plugins = [],
|
|
28
|
-
rollupOptions = {},
|
|
29
|
-
rollupFormat = "es",
|
|
30
|
-
...injectManifest
|
|
31
|
-
} = options;
|
|
32
|
-
|
|
33
|
-
const basePath = resolveBasePath(base);
|
|
34
|
-
// check typescript service worker for injectManifest strategy
|
|
35
|
-
const scope = _scope || basePath;
|
|
36
|
-
|
|
37
|
-
let assetsDir = slash(viteConfig.build.assetsDir ?? "assets");
|
|
38
|
-
if (assetsDir[assetsDir.length - 1] !== "/") assetsDir += "/";
|
|
39
|
-
|
|
40
|
-
const resolvedDevOptions: ResolvedPluginOptions["devOptions"] = {
|
|
41
|
-
bundle: true,
|
|
42
|
-
minify: false,
|
|
43
|
-
...devOptions,
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// remove './' prefix from assetsDir
|
|
47
|
-
const dontCacheBustURLsMatching = new RegExp(`^${assetsDir.replace(/^\.*?\//, "")}`);
|
|
48
|
-
|
|
49
|
-
const { validateViteInjectManifestOptions } = await loadSerwistBuild();
|
|
50
|
-
|
|
51
|
-
const validatedInjectManifest = await validateViteInjectManifestOptions(injectManifest);
|
|
52
|
-
|
|
53
|
-
const { swSrc, swDest, ...userInjectManifest } = validatedInjectManifest || {};
|
|
54
|
-
|
|
55
|
-
const resolvedPluginOptions = {
|
|
56
|
-
base: basePath,
|
|
57
|
-
type,
|
|
58
|
-
mode,
|
|
59
|
-
injectRegister,
|
|
60
|
-
registerType,
|
|
61
|
-
useCredentials,
|
|
62
|
-
swUrl,
|
|
63
|
-
injectManifest: {
|
|
64
|
-
dontCacheBustURLsMatching,
|
|
65
|
-
...userInjectManifest,
|
|
66
|
-
swSrc: path.resolve(viteConfig.root, swSrc),
|
|
67
|
-
swDest: path.resolve(viteConfig.root, viteConfig.build.outDir, swDest),
|
|
68
|
-
disablePrecacheManifest: !viteConfig.isProduction,
|
|
69
|
-
},
|
|
70
|
-
scope,
|
|
71
|
-
minify,
|
|
72
|
-
includeAssets,
|
|
73
|
-
disable,
|
|
74
|
-
integration,
|
|
75
|
-
buildBase: buildBase ?? basePath,
|
|
76
|
-
injectManifestRollupOptions: {
|
|
77
|
-
plugins,
|
|
78
|
-
rollupOptions,
|
|
79
|
-
format: rollupFormat,
|
|
80
|
-
},
|
|
81
|
-
devOptions: resolvedDevOptions,
|
|
82
|
-
} satisfies ResolvedPluginOptions;
|
|
83
|
-
|
|
84
|
-
// calculate hash only when required
|
|
85
|
-
const calculateHash = !resolvedPluginOptions.disable && resolvedPluginOptions.includeAssets && viteConfig.command === "build";
|
|
86
|
-
|
|
87
|
-
if (calculateHash) await configureStaticAssets(resolvedPluginOptions, viteConfig);
|
|
88
|
-
|
|
89
|
-
return resolvedPluginOptions;
|
|
90
|
-
};
|
package/src/types.ts
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import type { ManifestEntry, ViteInjectManifestOptions } from "@serwist/build";
|
|
2
|
-
import type { RollupOptions } from "rollup";
|
|
3
|
-
import type { BuildOptions, Plugin, ResolvedConfig } from "vite";
|
|
4
|
-
|
|
5
|
-
export type InjectManifestVitePlugins = string[] | ((vitePluginIds: string[]) => string[]);
|
|
6
|
-
export interface CustomInjectManifestOptions extends Omit<ViteInjectManifestOptions, "disablePrecacheManifest"> {
|
|
7
|
-
/**
|
|
8
|
-
* The URL to the service worker.
|
|
9
|
-
* @default "/sw.js"
|
|
10
|
-
*/
|
|
11
|
-
swUrl?: string;
|
|
12
|
-
/**
|
|
13
|
-
* Configure the format to use in the Rollup build.
|
|
14
|
-
*
|
|
15
|
-
* @default 'es'
|
|
16
|
-
*/
|
|
17
|
-
rollupFormat?: "es" | "iife";
|
|
18
|
-
/**
|
|
19
|
-
* Since `v0.15.0` you can add plugins to build your service worker.
|
|
20
|
-
*
|
|
21
|
-
* When using `injectManifest` there are 2 builds, your application and the service worker.
|
|
22
|
-
* If you're using custom configuration for your service worker (for example custom plugins) you can use this option to configure the service worker build.
|
|
23
|
-
* Both configurations cannot be shared, and so you'll need to duplicate the configuration, with the exception of `define`.
|
|
24
|
-
*
|
|
25
|
-
* **WARN**: this option is for advanced usage, be aware that you may break your application build.
|
|
26
|
-
*/
|
|
27
|
-
plugins?: Plugin[];
|
|
28
|
-
/**
|
|
29
|
-
* Since `v0.15.0` you can add custom Rollup options to build your service worker: we expose the same configuration to build a worker using Vite.
|
|
30
|
-
*/
|
|
31
|
-
rollupOptions?: Omit<RollupOptions, "plugins" | "output">;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface SerwistViteHooks {
|
|
35
|
-
beforeBuildServiceWorker?: (options: ResolvedPluginOptions) => void | Promise<void>;
|
|
36
|
-
closeBundleOrder?: "pre" | "post" | null;
|
|
37
|
-
configureOptions?: (viteOptions: ResolvedConfig, options: PluginOptions) => void | Promise<void>;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface DevOptions {
|
|
41
|
-
/**
|
|
42
|
-
* Whether the service worker should be bundled in development mode.
|
|
43
|
-
*
|
|
44
|
-
* [Many browsers still do not support ES Modules in service workers.](https://caniuse.com/mdn-api_serviceworker_ecmascript_modules) However, in development
|
|
45
|
-
* mode, certain frameworks, such as SvelteKit, do not bundle the service worker. As a result, trying to register that service worker on browsers lacking
|
|
46
|
-
* 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
|
|
47
|
-
* happening. What the plugin does is intercepting any request to the service worker (requests for `swUrl`) and returning a bundled one.
|
|
48
|
-
*/
|
|
49
|
-
bundle?: boolean;
|
|
50
|
-
minify?: BuildOptions["minify"];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Plugin options.
|
|
55
|
-
*/
|
|
56
|
-
export interface BasePluginOptions {
|
|
57
|
-
/**
|
|
58
|
-
* Build mode
|
|
59
|
-
*
|
|
60
|
-
* @default
|
|
61
|
-
* process.env.NODE_ENV // or "production" if undefined
|
|
62
|
-
*/
|
|
63
|
-
mode?: "development" | "production";
|
|
64
|
-
/**
|
|
65
|
-
* The service worker type.
|
|
66
|
-
*
|
|
67
|
-
* @default "classic"
|
|
68
|
-
*/
|
|
69
|
-
type?: WorkerType;
|
|
70
|
-
/**
|
|
71
|
-
* The scope to register the Service Worker
|
|
72
|
-
*
|
|
73
|
-
* @default `viteOptions.base`
|
|
74
|
-
*/
|
|
75
|
-
scope?: string;
|
|
76
|
-
/**
|
|
77
|
-
* Inject the service worker register inlined in the index.html
|
|
78
|
-
*
|
|
79
|
-
* If set to "auto", depends on whether you used the `import { registerSW } from 'virtual:pwa-register'`
|
|
80
|
-
* it will do nothing or use the `script` mode
|
|
81
|
-
*
|
|
82
|
-
* `"inline"` - inject a simple register, inlined with the generated html
|
|
83
|
-
*
|
|
84
|
-
* `"script"` - inject `<script/>` in `<head>` with `src` attribute to a generated script to register the service worker
|
|
85
|
-
*
|
|
86
|
-
* `"script-defer"` - inject `<script defer />` in `<head>`, with `src` attribute to a generated script to register the service worker
|
|
87
|
-
*
|
|
88
|
-
* `null` - do nothing. You will need to register the service worker yourself or import `registerSW` from `virtual:pwa-register`.
|
|
89
|
-
*
|
|
90
|
-
* @default "auto"
|
|
91
|
-
*/
|
|
92
|
-
injectRegister: "inline" | "script" | "script-defer" | "auto" | null | false;
|
|
93
|
-
/**
|
|
94
|
-
* Mode for the virtual register.
|
|
95
|
-
* This is NOT available if `injectRegister` is set to `"inline"` or `"script"`
|
|
96
|
-
*
|
|
97
|
-
* `"prompt"` - you will need to show a popup/dialog to the user to confirm the reload.
|
|
98
|
-
*
|
|
99
|
-
* `"autoUpdate"` - when new content is available, the new service worker will update caches and reload all browser
|
|
100
|
-
* windows/tabs with the application open automatically, it must take the control for the application to work
|
|
101
|
-
* properly.
|
|
102
|
-
*
|
|
103
|
-
* @default "prompt"
|
|
104
|
-
*/
|
|
105
|
-
registerType?: "prompt" | "autoUpdate";
|
|
106
|
-
/**
|
|
107
|
-
* Minify the generated manifest
|
|
108
|
-
*
|
|
109
|
-
* @default true
|
|
110
|
-
*/
|
|
111
|
-
minify: boolean;
|
|
112
|
-
/**
|
|
113
|
-
* Whether to add the `crossorigin="use-credentials"` attribute to `<link rel="manifest">`
|
|
114
|
-
* @default false
|
|
115
|
-
*/
|
|
116
|
-
useCredentials?: boolean;
|
|
117
|
-
/**
|
|
118
|
-
* Override Vite's base options for `@serwist/vite`.
|
|
119
|
-
*
|
|
120
|
-
* @default viteOptions.base
|
|
121
|
-
*/
|
|
122
|
-
base?: string;
|
|
123
|
-
/**
|
|
124
|
-
* `public` resources to be added to the PWA manifest.
|
|
125
|
-
*
|
|
126
|
-
* You don't need to add `manifest` icons here, it will be auto included.
|
|
127
|
-
*
|
|
128
|
-
* The `public` directory will be resolved from Vite's `publicDir` option directory.
|
|
129
|
-
*/
|
|
130
|
-
includeAssets: string | string[] | undefined;
|
|
131
|
-
/**
|
|
132
|
-
* Whether Serwist should be disabled.
|
|
133
|
-
*
|
|
134
|
-
* @default false
|
|
135
|
-
*/
|
|
136
|
-
disable: boolean;
|
|
137
|
-
/**
|
|
138
|
-
* `@serwist/vite` integration.
|
|
139
|
-
*/
|
|
140
|
-
integration?: SerwistViteHooks;
|
|
141
|
-
/**
|
|
142
|
-
* When Vite's build folder is not the same as your base root folder, configure it here.
|
|
143
|
-
*
|
|
144
|
-
* This option will be useful for integrations like `vite-plugin-laravel` where Vite's build folder is `public/build` but Laravel's base path is `public`.
|
|
145
|
-
*
|
|
146
|
-
* This option will be used to configure the path for the service worker, "registerSW.js" and the web manifest assets.
|
|
147
|
-
*
|
|
148
|
-
* For example, if your base path is `/`, then, in your Laravel PWA configuration use `buildPath: '/build/'`.
|
|
149
|
-
*
|
|
150
|
-
* By default: `vite.base`.
|
|
151
|
-
*/
|
|
152
|
-
buildBase?: string;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export interface PluginOptions extends Partial<BasePluginOptions>, CustomInjectManifestOptions {
|
|
156
|
-
devOptions?: DevOptions;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export interface InjectManifestRollupOptions {
|
|
160
|
-
format: "es" | "iife";
|
|
161
|
-
plugins: Plugin[];
|
|
162
|
-
rollupOptions: RollupOptions;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export interface ResolvedPluginOptions extends Required<BasePluginOptions>, Required<Pick<CustomInjectManifestOptions, "swUrl">> {
|
|
166
|
-
injectManifest: ViteInjectManifestOptions;
|
|
167
|
-
injectManifestRollupOptions: InjectManifestRollupOptions;
|
|
168
|
-
devOptions: Required<DevOptions>;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export interface ShareTargetFiles {
|
|
172
|
-
name: string;
|
|
173
|
-
accept: string | string[];
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/Manifest/launch_handler#launch_handler_item_values
|
|
178
|
-
*/
|
|
179
|
-
export type LaunchHandlerClientMode = "auto" | "focus-existing" | "navigate-existing" | "navigate-new";
|
|
180
|
-
|
|
181
|
-
export type Display = "fullscreen" | "standalone" | "minimal-ui" | "browser";
|
|
182
|
-
export type DisplayOverride = Display | "window-controls-overlay";
|
|
183
|
-
export type IconPurpose = "monochrome" | "maskable" | "any";
|
|
184
|
-
|
|
185
|
-
// biome-ignore lint/complexity/noBannedTypes: We intentionally have this.
|
|
186
|
-
type Nothing = {};
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* type StringLiteralUnion<'maskable'> = 'maskable' | string
|
|
190
|
-
* This has auto completion whereas `'maskable' | string` doesn't
|
|
191
|
-
* Adapted from https://github.com/microsoft/TypeScript/issues/29729
|
|
192
|
-
*/
|
|
193
|
-
export type StringLiteralUnion<T extends U, U = string> = T | (U & Nothing);
|
|
194
|
-
|
|
195
|
-
export interface SerwistViteApi {
|
|
196
|
-
/**
|
|
197
|
-
* Is the plugin disabled?
|
|
198
|
-
*/
|
|
199
|
-
disabled: boolean;
|
|
200
|
-
extendManifestEntries(fn: ExtendManifestEntriesHook): void;
|
|
201
|
-
/*
|
|
202
|
-
* Generate the service worker.
|
|
203
|
-
*/
|
|
204
|
-
generateSW(): Promise<void>;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
export type ExtendManifestEntriesHook = (manifestEntries: (string | ManifestEntry)[]) => (string | ManifestEntry)[] | undefined;
|
package/src/utils-types.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type Optional<T, U extends keyof T> = Omit<T, U> & Partial<Pick<T, U>>;
|
package/src/virtual.d.ts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|