@serwist/vite 9.0.0-preview.24 → 9.0.0-preview.25

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.js CHANGED
@@ -7,7 +7,7 @@ import { validationErrorMap, SerwistConfigError } from '@serwist/build/schema';
7
7
  import { normalizePath } from 'vite';
8
8
  import process from 'node:process';
9
9
 
10
- var version = "9.0.0-preview.24";
10
+ var version = "9.0.0-preview.25";
11
11
 
12
12
  const logSerwistResult = (buildResult, viteOptions)=>{
13
13
  const { logLevel = "info" } = viteOptions;
@@ -257,7 +257,7 @@ const buildPlugin = (ctx, api)=>{
257
257
  }
258
258
  }
259
259
  },
260
- async buildEnd (error) {
260
+ buildEnd (error) {
261
261
  if (error) throw error;
262
262
  }
263
263
  };
@@ -303,8 +303,8 @@ const devPlugin = (ctx, api)=>{
303
303
  };
304
304
  };
305
305
 
306
- const INTERNAL_SERWIST_VIRTUAL = "virtual:internal-serwist";
307
- const RESOLVED_INTERNAL_SERWIST_VIRTUAL = `\0${INTERNAL_SERWIST_VIRTUAL}`;
306
+ const SERWIST_VIRTUAL = "virtual:serwist";
307
+ const RESOLVED_SERWIST_VIRTUAL = `\0${SERWIST_VIRTUAL}`;
308
308
 
309
309
  const prepareConfigForValidation = (viteConfig, { mode = process.env.NODE_ENV === "production" || process.env.NODE_ENV === "development" ? process.env.NODE_ENV : "production", base = viteConfig.base, scope: _scope, devOptions, ...injectManifest })=>{
310
310
  const basePath = resolveBasePath(base);
@@ -361,13 +361,13 @@ const mainPlugin = (ctx, api)=>{
361
361
  ctx.options = await resolveOptions(ctx.userOptions, config);
362
362
  },
363
363
  resolveId (id) {
364
- if (id === INTERNAL_SERWIST_VIRTUAL) {
365
- return RESOLVED_INTERNAL_SERWIST_VIRTUAL;
364
+ if (id === SERWIST_VIRTUAL) {
365
+ return RESOLVED_SERWIST_VIRTUAL;
366
366
  }
367
367
  return undefined;
368
368
  },
369
369
  load (id) {
370
- if (id === RESOLVED_INTERNAL_SERWIST_VIRTUAL) {
370
+ if (id === RESOLVED_SERWIST_VIRTUAL) {
371
371
  return `export const swUrl = "${path.posix.join(ctx.options.base, ctx.options.swUrl)}";
372
372
  export const swScope = "${ctx.options.scope}";
373
373
  export const swType = "${ctx.devEnvironment ? "module" : ctx.options.type}";`;
@@ -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,SAAS,CAAC;AAI9C;;;;;GAKG;AACH,eAAO,MAAM,YAAY,EAAE,cAAc,EA8GpC,CAAC"}
1
+ {"version":3,"file":"index.worker.d.ts","sourceRoot":"","sources":["../src/index.worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG9C;;;;;GAKG;AACH,eAAO,MAAM,YAAY,EAAE,cAAc,EA8GpC,CAAC"}
@@ -1,5 +1,4 @@
1
- import { ExpirationPlugin } from 'serwist/plugins';
2
- import { CacheFirst, StaleWhileRevalidate, NetworkFirst } from 'serwist/strategies';
1
+ import { CacheFirst, ExpirationPlugin, StaleWhileRevalidate, NetworkFirst } from 'serwist';
3
2
 
4
3
  const defaultCache = import.meta.env.DEV ? [] : [
5
4
  {
@@ -1,3 +1,3 @@
1
- export declare const INTERNAL_SERWIST_VIRTUAL = "virtual:internal-serwist";
2
- export declare const RESOLVED_INTERNAL_SERWIST_VIRTUAL = "\0virtual:internal-serwist";
1
+ export declare const SERWIST_VIRTUAL = "virtual:serwist";
2
+ export declare const RESOLVED_SERWIST_VIRTUAL = "\0virtual:serwist";
3
3
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/lib/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,6BAA6B,CAAC;AACnE,eAAO,MAAM,iCAAiC,+BAAkC,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/lib/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,oBAAoB,CAAC;AACjD,eAAO,MAAM,wBAAwB,sBAAyB,CAAC"}
@@ -56,9 +56,9 @@ export declare const injectManifestPartial: z.ZodObject<{
56
56
  minify?: boolean | "terser" | "esbuild" | undefined;
57
57
  }>>;
58
58
  }, "strip", z.ZodTypeAny, {
59
- scope: string;
60
59
  type: "classic" | "module";
61
60
  mode: "development" | "production";
61
+ scope: string;
62
62
  base: string;
63
63
  disable: boolean;
64
64
  integration: {
@@ -75,8 +75,8 @@ export declare const injectManifestPartial: z.ZodObject<{
75
75
  minify: boolean | "terser" | "esbuild";
76
76
  };
77
77
  }, {
78
- scope: string;
79
78
  mode: "development" | "production";
79
+ scope: string;
80
80
  base: string;
81
81
  type?: "classic" | "module" | undefined;
82
82
  disable?: boolean | undefined;
@@ -238,9 +238,9 @@ export declare const injectManifestOptions: z.ZodObject<{
238
238
  minify?: boolean | "terser" | "esbuild" | undefined;
239
239
  }>>;
240
240
  }, "strict", z.ZodTypeAny, {
241
- scope: string;
242
241
  type: "classic" | "module";
243
242
  mode: "development" | "production";
243
+ scope: string;
244
244
  base: string;
245
245
  disable: boolean;
246
246
  integration: {
@@ -297,8 +297,8 @@ export declare const injectManifestOptions: z.ZodObject<{
297
297
  modifyURLPrefix?: Record<string, string> | undefined;
298
298
  templatedURLs?: Record<string, string | string[]> | undefined;
299
299
  }, {
300
- scope: string;
301
300
  mode: "development" | "production";
301
+ scope: string;
302
302
  base: string;
303
303
  swSrc: string;
304
304
  swDest: string;
@@ -4,28 +4,34 @@ import type { RollupOptions } from "rollup";
4
4
  import type { BuildOptions, Plugin, ResolvedConfig } from "vite";
5
5
  export interface InjectPartial {
6
6
  /**
7
- * The mode in which Serwist should be built.
7
+ * The mode in which your service worker should be built.
8
8
  *
9
9
  * @default
10
10
  * process.env.NODE_ENV // or "production" if undefined
11
11
  */
12
12
  mode?: "development" | "production";
13
13
  /**
14
- * The service worker type.
14
+ * The module type with which the service worker should be registered. Usually used alongside
15
+ * `rollupFormat`.
15
16
  *
16
17
  * @default "classic"
18
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register#type
17
19
  */
18
20
  type?: WorkerType;
19
21
  /**
20
- * The scope with which Serwist should register the service worker.
22
+ * The service worker's URL scope. Set to `"/foo/"` so that paths under "/foo/"
23
+ * are under the service worker's control while others are not.
21
24
  *
22
25
  * @default viteOptions.base
26
+ * @see https://vitejs.dev/config/shared-options.html#base
27
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register#scope
23
28
  */
24
29
  scope?: string;
25
30
  /**
26
31
  * The base from which Serwist resolves URLs.
27
32
  *
28
33
  * @default viteOptions.base
34
+ * @see https://vitejs.dev/config/shared-options.html#base
29
35
  */
30
36
  base?: string;
31
37
  /**
@@ -45,7 +51,7 @@ export interface InjectPartial {
45
51
  */
46
52
  swUrl?: string;
47
53
  /**
48
- * Plugins used to build your service worker.
54
+ * Rollup/Vite plugins used to build the service worker.
49
55
  */
50
56
  plugins?: Plugin[];
51
57
  /**
@@ -71,19 +77,28 @@ export interface InjectManifestOptions extends Omit<BasePartial, "disablePrecach
71
77
  export interface InjectManifestOptionsComplete extends BaseResolved, GlobResolved, BaseInjectResolved, RequiredSwDestResolved, RequiredGlobDirectoryResolved, InjectResolved {
72
78
  }
73
79
  export interface Hooks {
80
+ /**
81
+ * Allows you to run some logic before the service worker is built.
82
+ * @param options
83
+ * @returns
84
+ */
74
85
  beforeBuildServiceWorker?: (options: PluginOptionsComplete) => void | Promise<void>;
86
+ /**
87
+ * Adjusts the application order of `@serwist/vite`'s `closeBundle` hook.
88
+ */
75
89
  closeBundleOrder?: "pre" | "post" | null;
90
+ /**
91
+ * Allows you to configure the options of Serwist and Vite. Useful when there is a dependency between the two.
92
+ * @param viteOptions
93
+ * @param options
94
+ * @returns
95
+ */
76
96
  configureOptions?: (viteOptions: ResolvedConfig, options: PluginOptions) => void | Promise<void>;
77
97
  }
78
98
  export interface DevOptions {
79
99
  /**
80
100
  * Whether the service worker should be bundled in development mode.
81
101
  *
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
102
  * @default true
88
103
  */
89
104
  bundle?: boolean;
@@ -99,17 +114,6 @@ export interface PluginOptions extends InjectManifestOptions {
99
114
  export interface PluginOptionsComplete extends InjectResolved {
100
115
  injectManifest: Omit<InjectManifestOptionsComplete, keyof InjectResolved>;
101
116
  }
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
117
  export interface SerwistViteApi {
114
118
  /**
115
119
  * Whether the plugin is disabled.
@@ -123,5 +127,4 @@ export interface SerwistViteApi {
123
127
  generateSW(): Promise<void>;
124
128
  }
125
129
  export type ExtendManifestEntriesHook = (manifestEntries: (string | ManifestEntry)[]) => (string | ManifestEntry)[] | undefined;
126
- export {};
127
130
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,aAAa,IAAI,iBAAiB,EAClC,cAAc,IAAI,kBAAkB,EACp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AAc;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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/vite",
3
- "version": "9.0.0-preview.24",
3
+ "version": "9.0.0-preview.25",
4
4
  "type": "module",
5
5
  "description": "A module that integrates Serwist into your Vite application.",
6
6
  "files": [
@@ -30,22 +30,22 @@
30
30
  },
31
31
  "author": "antfu <anthonyfu117@hotmail.com>, Serwist's Team",
32
32
  "license": "MIT",
33
- "repository": "https://gitlab.com/serwist/serwist",
34
- "bugs": "https://gitlab.com/serwist/serwist/issues",
33
+ "repository": "https://github.com/serwist/serwist",
34
+ "bugs": "https://github.com/serwist/serwist/issues",
35
35
  "homepage": "https://serwist.pages.dev",
36
36
  "sideEffects": false,
37
37
  "main": "./dist/index.js",
38
38
  "types": "./dist/index.d.ts",
39
39
  "typesVersions": {
40
40
  "*": {
41
- "browser": [
42
- "./dist/index.browser.d.ts"
43
- ],
44
41
  "worker": [
45
42
  "./dist/index.worker.d.ts"
46
43
  ],
47
44
  "schema": [
48
45
  "./dist/index.schema.d.ts"
46
+ ],
47
+ "typings": [
48
+ "./typings.d.ts"
49
49
  ]
50
50
  }
51
51
  },
@@ -54,10 +54,6 @@
54
54
  "types": "./dist/index.d.ts",
55
55
  "default": "./dist/index.js"
56
56
  },
57
- "./browser": {
58
- "types": "./dist/index.browser.d.ts",
59
- "default": "./dist/index.browser.js"
60
- },
61
57
  "./worker": {
62
58
  "types": "./dist/index.worker.d.ts",
63
59
  "default": "./dist/index.worker.js"
@@ -66,24 +62,27 @@
66
62
  "types": "./dist/index.schema.d.ts",
67
63
  "default": "./dist/index.schema.js"
68
64
  },
65
+ "./typings": {
66
+ "types": "./typings.d.ts"
67
+ },
69
68
  "./package.json": "./package.json"
70
69
  },
71
70
  "dependencies": {
72
71
  "glob": "10.3.12",
73
72
  "kolorist": "1.8.0",
74
73
  "zod": "3.22.4",
75
- "@serwist/build": "9.0.0-preview.24",
76
- "serwist": "9.0.0-preview.24",
77
- "@serwist/window": "9.0.0-preview.24"
74
+ "@serwist/build": "9.0.0-preview.25",
75
+ "serwist": "9.0.0-preview.25",
76
+ "@serwist/window": "9.0.0-preview.25"
78
77
  },
79
78
  "devDependencies": {
80
- "@types/node": "20.12.4",
81
- "rollup": "4.14.0",
82
- "typescript": "5.5.0-dev.20240404",
79
+ "@types/node": "20.12.7",
80
+ "rollup": "4.14.3",
81
+ "typescript": "5.5.0-dev.20240415",
83
82
  "vite": "5.2.8",
84
- "@serwist/constants": "9.0.0-preview.24",
85
- "serwist": "9.0.0-preview.24",
86
- "@serwist/utils": "9.0.0-preview.24"
83
+ "@serwist/configs": "9.0.0-preview.25",
84
+ "@serwist/utils": "9.0.0-preview.25",
85
+ "serwist": "9.0.0-preview.25"
87
86
  },
88
87
  "peerDependencies": {
89
88
  "typescript": ">=5.0.0",
@@ -1,6 +1,5 @@
1
1
  import type { RuntimeCaching } from "serwist";
2
- import { ExpirationPlugin } from "serwist/plugins";
3
- import { CacheFirst, NetworkFirst, StaleWhileRevalidate } from "serwist/strategies";
2
+ import { CacheFirst, ExpirationPlugin, NetworkFirst, StaleWhileRevalidate } from "serwist";
4
3
 
5
4
  /**
6
5
  * The default, recommended list of caching strategies for applications
@@ -1,2 +1,2 @@
1
- export const INTERNAL_SERWIST_VIRTUAL = "virtual:internal-serwist";
2
- export const RESOLVED_INTERNAL_SERWIST_VIRTUAL = `\0${INTERNAL_SERWIST_VIRTUAL}`;
1
+ export const SERWIST_VIRTUAL = "virtual:serwist";
2
+ export const RESOLVED_SERWIST_VIRTUAL = `\0${SERWIST_VIRTUAL}`;
package/src/lib/types.ts CHANGED
@@ -17,28 +17,34 @@ import type { BuildOptions, Plugin, ResolvedConfig } from "vite";
17
17
 
18
18
  export interface InjectPartial {
19
19
  /**
20
- * The mode in which Serwist should be built.
20
+ * The mode in which your service worker should be built.
21
21
  *
22
22
  * @default
23
23
  * process.env.NODE_ENV // or "production" if undefined
24
24
  */
25
25
  mode?: "development" | "production";
26
26
  /**
27
- * The service worker type.
27
+ * The module type with which the service worker should be registered. Usually used alongside
28
+ * `rollupFormat`.
28
29
  *
29
30
  * @default "classic"
31
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register#type
30
32
  */
31
33
  type?: WorkerType;
32
34
  /**
33
- * The scope with which Serwist should register the service worker.
35
+ * The service worker's URL scope. Set to `"/foo/"` so that paths under "/foo/"
36
+ * are under the service worker's control while others are not.
34
37
  *
35
38
  * @default viteOptions.base
39
+ * @see https://vitejs.dev/config/shared-options.html#base
40
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register#scope
36
41
  */
37
42
  scope?: string;
38
43
  /**
39
44
  * The base from which Serwist resolves URLs.
40
45
  *
41
46
  * @default viteOptions.base
47
+ * @see https://vitejs.dev/config/shared-options.html#base
42
48
  */
43
49
  base?: string;
44
50
  /**
@@ -58,7 +64,7 @@ export interface InjectPartial {
58
64
  */
59
65
  swUrl?: string;
60
66
  /**
61
- * Plugins used to build your service worker.
67
+ * Rollup/Vite plugins used to build the service worker.
62
68
  */
63
69
  plugins?: Plugin[];
64
70
  /**
@@ -98,8 +104,22 @@ export interface InjectManifestOptionsComplete
98
104
  InjectResolved {}
99
105
 
100
106
  export interface Hooks {
107
+ /**
108
+ * Allows you to run some logic before the service worker is built.
109
+ * @param options
110
+ * @returns
111
+ */
101
112
  beforeBuildServiceWorker?: (options: PluginOptionsComplete) => void | Promise<void>;
113
+ /**
114
+ * Adjusts the application order of `@serwist/vite`'s `closeBundle` hook.
115
+ */
102
116
  closeBundleOrder?: "pre" | "post" | null;
117
+ /**
118
+ * Allows you to configure the options of Serwist and Vite. Useful when there is a dependency between the two.
119
+ * @param viteOptions
120
+ * @param options
121
+ * @returns
122
+ */
103
123
  configureOptions?: (viteOptions: ResolvedConfig, options: PluginOptions) => void | Promise<void>;
104
124
  }
105
125
 
@@ -107,11 +127,6 @@ export interface DevOptions {
107
127
  /**
108
128
  * Whether the service worker should be bundled in development mode.
109
129
  *
110
- * Many browsers still [do not support ES Modules in service workers](https://caniuse.com/mdn-api_serviceworker_ecmascript_modules). However, in development
111
- * mode, certain frameworks, such as SvelteKit, do not bundle the service worker. As a result, trying to register that service worker on browsers lacking
112
- * 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
113
- * happening. What the plugin does is intercepting any request to the service worker (requests for `swUrl`) and returning a bundled one.
114
- *
115
130
  * @default true
116
131
  */
117
132
  bundle?: boolean;
@@ -129,21 +144,6 @@ export interface PluginOptionsComplete extends InjectResolved {
129
144
  injectManifest: Omit<InjectManifestOptionsComplete, keyof InjectResolved>;
130
145
  }
131
146
 
132
- export interface ShareTargetFiles {
133
- name: string;
134
- accept: string | string[];
135
- }
136
-
137
- // biome-ignore lint/complexity/noBannedTypes: We intentionally do this.
138
- type Nothing = {};
139
-
140
- /**
141
- * type StringLiteralUnion<'maskable'> = 'maskable' | string
142
- * This has auto completion whereas `'maskable' | string` doesn't
143
- * Adapted from https://github.com/microsoft/TypeScript/issues/29729
144
- */
145
- export type StringLiteralUnion<T extends U, U = string> = T | (U & Nothing);
146
-
147
147
  export interface SerwistViteApi {
148
148
  /**
149
149
  * Whether the plugin is disabled.
@@ -24,7 +24,7 @@ export const buildPlugin = (ctx: SerwistViteContext, api: SerwistViteApi) => {
24
24
  }
25
25
  },
26
26
  },
27
- async buildEnd(error) {
27
+ buildEnd(error) {
28
28
  if (error) throw error;
29
29
  },
30
30
  };
@@ -2,7 +2,7 @@ import path from "node:path";
2
2
 
3
3
  import type { Plugin, UserConfig } from "vite";
4
4
 
5
- import { INTERNAL_SERWIST_VIRTUAL, RESOLVED_INTERNAL_SERWIST_VIRTUAL } from "../lib/constants.js";
5
+ import { SERWIST_VIRTUAL, RESOLVED_SERWIST_VIRTUAL } from "../lib/constants.js";
6
6
  import type { SerwistViteContext } from "../lib/context.js";
7
7
  import { resolveOptions } from "../lib/options.js";
8
8
  import type { SerwistViteApi } from "../lib/types.js";
@@ -31,13 +31,13 @@ export const mainPlugin = (ctx: SerwistViteContext, api: SerwistViteApi) => {
31
31
  ctx.options = await resolveOptions(ctx.userOptions, config);
32
32
  },
33
33
  resolveId(id) {
34
- if (id === INTERNAL_SERWIST_VIRTUAL) {
35
- return RESOLVED_INTERNAL_SERWIST_VIRTUAL;
34
+ if (id === SERWIST_VIRTUAL) {
35
+ return RESOLVED_SERWIST_VIRTUAL;
36
36
  }
37
37
  return undefined;
38
38
  },
39
39
  load(id) {
40
- if (id === RESOLVED_INTERNAL_SERWIST_VIRTUAL) {
40
+ if (id === RESOLVED_SERWIST_VIRTUAL) {
41
41
  return `export const swUrl = "${path.posix.join(ctx.options.base, ctx.options.swUrl)}";
42
42
  export const swScope = "${ctx.options.scope}";
43
43
  export const swType = "${ctx.devEnvironment ? "module" : ctx.options.type}";`;
package/src/rollup.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // @ts-check
2
- import { getRollupOptions } from "@serwist/constants/rollup";
2
+ import { getRollupOptions } from "@serwist/configs/rollup";
3
3
 
4
4
  import packageJson from "../package.json" assert { type: "json" };
5
5
 
@@ -9,7 +9,6 @@ export default getRollupOptions({
9
9
  {
10
10
  input: {
11
11
  index: "src/index.ts",
12
- "index.browser": "src/index.browser.ts",
13
12
  "index.worker": "src/index.worker.ts",
14
13
  "index.schema": "src/index.schema.ts",
15
14
  },
@@ -19,7 +18,6 @@ export default getRollupOptions({
19
18
  chunkFileNames: "chunks/[name].js",
20
19
  format: "esm",
21
20
  },
22
- external: ["virtual:internal-serwist"],
23
21
  },
24
22
  ],
25
23
  });
@@ -1,2 +0,0 @@
1
- export declare const getSerwist: () => Promise<import("@serwist/window").Serwist | undefined>;
2
- //# sourceMappingURL=index.browser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,8DAKtB,CAAC"}
@@ -1,13 +0,0 @@
1
- import { swUrl, swScope, swType } from 'virtual:internal-serwist';
2
-
3
- const getSerwist = async ()=>{
4
- if ("serviceWorker" in navigator) {
5
- return new (await import('@serwist/window')).Serwist(swUrl, {
6
- scope: swScope,
7
- type: swType
8
- });
9
- }
10
- return undefined;
11
- };
12
-
13
- export { getSerwist };
@@ -1,8 +0,0 @@
1
- import { swScope, swType, swUrl } from "virtual:internal-serwist";
2
-
3
- export const getSerwist = async () => {
4
- if ("serviceWorker" in navigator) {
5
- return new (await import("@serwist/window")).Serwist(swUrl, { scope: swScope, type: swType });
6
- }
7
- return undefined;
8
- };
package/src/virtual.d.ts DELETED
@@ -1,5 +0,0 @@
1
- declare module "virtual:internal-serwist" {
2
- export const swUrl: string;
3
- export const swScope: string;
4
- export const swType: WorkerType;
5
- }