@serwist/vite 9.0.0-preview.12 → 9.0.0-preview.14
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 +65 -174
- 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/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} +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 +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 +23 -53
- package/src/index.schema.ts +3 -0
- package/src/index.ts +8 -7
- 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 +2 -2
- package/src/plugins/dev.ts +3 -3
- package/src/plugins/main.ts +5 -5
- package/src/rollup.js +3 -2
- 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/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/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
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 };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ResolvedConfig } from "vite";
|
|
2
2
|
|
|
3
|
-
import type { PluginOptions,
|
|
3
|
+
import type { PluginOptions, PluginOptionsComplete } from "./types.js";
|
|
4
4
|
|
|
5
5
|
export type SerwistViteFrameworks = "nuxt";
|
|
6
6
|
|
|
@@ -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.GetManifestOptions): 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
|
|
|
@@ -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,
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
|
|
4
|
+
import type { ResolvedConfig } from "vite";
|
|
5
|
+
|
|
6
|
+
import type { PluginOptions, PluginOptionsComplete } from "./types.js";
|
|
7
|
+
import { resolveBasePath, slash } from "./utils.js";
|
|
8
|
+
import { validateInjectManifestOptions } from "./validator.js";
|
|
9
|
+
|
|
10
|
+
const prepareConfigForValidation = (
|
|
11
|
+
viteConfig: ResolvedConfig,
|
|
12
|
+
{
|
|
13
|
+
mode = process.env.NODE_ENV === "production" || process.env.NODE_ENV === "development" ? process.env.NODE_ENV : "production",
|
|
14
|
+
base = viteConfig.base,
|
|
15
|
+
scope: _scope,
|
|
16
|
+
devOptions,
|
|
17
|
+
...injectManifest
|
|
18
|
+
}: PluginOptions,
|
|
19
|
+
) => {
|
|
20
|
+
const basePath = resolveBasePath(base);
|
|
21
|
+
return {
|
|
22
|
+
mode,
|
|
23
|
+
base: basePath,
|
|
24
|
+
scope: _scope || basePath,
|
|
25
|
+
devOptions,
|
|
26
|
+
...injectManifest,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const resolveOptions = async (options: PluginOptions, viteConfig: ResolvedConfig): Promise<PluginOptionsComplete> => {
|
|
31
|
+
const {
|
|
32
|
+
mode,
|
|
33
|
+
type,
|
|
34
|
+
scope,
|
|
35
|
+
base,
|
|
36
|
+
disable,
|
|
37
|
+
integration,
|
|
38
|
+
swUrl,
|
|
39
|
+
swSrc,
|
|
40
|
+
swDest,
|
|
41
|
+
plugins,
|
|
42
|
+
rollupFormat,
|
|
43
|
+
rollupOptions,
|
|
44
|
+
devOptions,
|
|
45
|
+
...userInjectManifest
|
|
46
|
+
} = await validateInjectManifestOptions(prepareConfigForValidation(viteConfig, options));
|
|
47
|
+
|
|
48
|
+
let assetsDir = slash(viteConfig.build.assetsDir ?? "assets");
|
|
49
|
+
if (assetsDir[assetsDir.length - 1] !== "/") assetsDir += "/";
|
|
50
|
+
|
|
51
|
+
// remove './' prefix from assetsDir
|
|
52
|
+
const dontCacheBustURLsMatching = new RegExp(`^${assetsDir.replace(/^\.*?\//, "")}`);
|
|
53
|
+
|
|
54
|
+
const resolvedPluginOptions = {
|
|
55
|
+
mode,
|
|
56
|
+
type,
|
|
57
|
+
scope,
|
|
58
|
+
base,
|
|
59
|
+
disable,
|
|
60
|
+
integration,
|
|
61
|
+
swUrl,
|
|
62
|
+
plugins,
|
|
63
|
+
rollupFormat,
|
|
64
|
+
rollupOptions,
|
|
65
|
+
devOptions,
|
|
66
|
+
injectManifest: {
|
|
67
|
+
dontCacheBustURLsMatching,
|
|
68
|
+
...userInjectManifest,
|
|
69
|
+
swSrc: path.resolve(viteConfig.root, swSrc),
|
|
70
|
+
swDest: path.resolve(viteConfig.root, viteConfig.build.outDir, swDest),
|
|
71
|
+
disablePrecacheManifest: !viteConfig.isProduction,
|
|
72
|
+
},
|
|
73
|
+
} satisfies PluginOptionsComplete;
|
|
74
|
+
|
|
75
|
+
return resolvedPluginOptions;
|
|
76
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { basePartial, globPartial, injectPartial, requiredGlobDirectoryPartial, requiredSwDestPartial } from "@serwist/build/schema";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
export const hooks = z.object({
|
|
5
|
+
beforeBuildServiceWorker: z.function(z.tuple([z.any()]), z.union([z.promise(z.void()), z.void()])).optional(),
|
|
6
|
+
closeBundleOrder: z.union([z.literal("pre"), z.literal("post"), z.null()]).optional(),
|
|
7
|
+
configureOptions: z.function(z.tuple([z.any(), z.any()]), z.union([z.promise(z.void()), z.void()])).optional(),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export const devOptions = z.object({
|
|
11
|
+
bundle: z.boolean().default(true),
|
|
12
|
+
minify: z.union([z.boolean(), z.literal("terser"), z.literal("esbuild")]).default(false),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const injectManifestPartial = z.object({
|
|
16
|
+
mode: z.union([z.literal("development"), z.literal("production")]),
|
|
17
|
+
type: z.union([z.literal("classic"), z.literal("module")]).default("classic"),
|
|
18
|
+
scope: z.string(),
|
|
19
|
+
base: z.string(),
|
|
20
|
+
disable: z.boolean().default(false),
|
|
21
|
+
integration: hooks.default({}),
|
|
22
|
+
swUrl: z.string().default("/sw.js"),
|
|
23
|
+
plugins: z.array(z.any()).default([]),
|
|
24
|
+
rollupFormat: z.union([z.literal("es"), z.literal("iife")]).default("es"),
|
|
25
|
+
rollupOptions: z.record(z.string(), z.any()).default({}),
|
|
26
|
+
devOptions: devOptions.default({}),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export const injectManifestOptions = basePartial
|
|
30
|
+
.merge(globPartial)
|
|
31
|
+
.merge(injectPartial)
|
|
32
|
+
.merge(requiredSwDestPartial)
|
|
33
|
+
.merge(requiredGlobDirectoryPartial)
|
|
34
|
+
.merge(injectManifestPartial)
|
|
35
|
+
.strict("Do not pass invalid properties to InjectManifestOptions!");
|
package/src/lib/types.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BasePartial,
|
|
3
|
+
BaseResolved,
|
|
4
|
+
GlobPartial,
|
|
5
|
+
GlobResolved,
|
|
6
|
+
InjectPartial as BaseInjectPartial,
|
|
7
|
+
InjectResolved as BaseInjectResolved,
|
|
8
|
+
ManifestEntry,
|
|
9
|
+
RequiredGlobDirectoryPartial,
|
|
10
|
+
RequiredGlobDirectoryResolved,
|
|
11
|
+
RequiredSwDestPartial,
|
|
12
|
+
RequiredSwDestResolved,
|
|
13
|
+
} from "@serwist/build";
|
|
14
|
+
import type { Require } from "@serwist/utils";
|
|
15
|
+
import type { RollupOptions } from "rollup";
|
|
16
|
+
import type { BuildOptions, Plugin, ResolvedConfig } from "vite";
|
|
17
|
+
|
|
18
|
+
export interface InjectPartial {
|
|
19
|
+
/**
|
|
20
|
+
* The mode in which Serwist should be built.
|
|
21
|
+
*
|
|
22
|
+
* @default
|
|
23
|
+
* process.env.NODE_ENV // or "production" if undefined
|
|
24
|
+
*/
|
|
25
|
+
mode?: "development" | "production";
|
|
26
|
+
/**
|
|
27
|
+
* The service worker type.
|
|
28
|
+
*
|
|
29
|
+
* @default "classic"
|
|
30
|
+
*/
|
|
31
|
+
type?: WorkerType;
|
|
32
|
+
/**
|
|
33
|
+
* The scope with which Serwist should register the service worker.
|
|
34
|
+
*
|
|
35
|
+
* @default viteOptions.base
|
|
36
|
+
*/
|
|
37
|
+
scope?: string;
|
|
38
|
+
/**
|
|
39
|
+
* The base from which Serwist resolves URLs.
|
|
40
|
+
*
|
|
41
|
+
* @default viteOptions.base
|
|
42
|
+
*/
|
|
43
|
+
base?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Whether Serwist should be disabled.
|
|
46
|
+
*
|
|
47
|
+
* @default false
|
|
48
|
+
*/
|
|
49
|
+
disable?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Hooks of the build lifecycle.
|
|
52
|
+
*/
|
|
53
|
+
integration?: Hooks;
|
|
54
|
+
/**
|
|
55
|
+
* The URL to the service worker.
|
|
56
|
+
*
|
|
57
|
+
* @default "/sw.js"
|
|
58
|
+
*/
|
|
59
|
+
swUrl?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Plugins used to build your service worker.
|
|
62
|
+
*/
|
|
63
|
+
plugins?: Plugin[];
|
|
64
|
+
/**
|
|
65
|
+
* The format used to build the service worker.
|
|
66
|
+
*
|
|
67
|
+
* @default "es"
|
|
68
|
+
*/
|
|
69
|
+
rollupFormat?: "es" | "iife";
|
|
70
|
+
/**
|
|
71
|
+
* Custom Rollup options used to build the service worker.
|
|
72
|
+
*/
|
|
73
|
+
rollupOptions?: Omit<RollupOptions, "plugins" | "output">;
|
|
74
|
+
/**
|
|
75
|
+
* Development-specific options.
|
|
76
|
+
*/
|
|
77
|
+
devOptions?: DevOptions;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface InjectResolved extends Require<InjectPartial, "mode" | "type" | "scope" | "base" | "disable" | "swUrl" | "rollupFormat"> {
|
|
81
|
+
devOptions: Required<DevOptions>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface InjectManifestOptions
|
|
85
|
+
extends Omit<BasePartial, "disablePrecacheManifest">,
|
|
86
|
+
GlobPartial,
|
|
87
|
+
BaseInjectPartial,
|
|
88
|
+
RequiredSwDestPartial,
|
|
89
|
+
RequiredGlobDirectoryPartial,
|
|
90
|
+
InjectPartial {}
|
|
91
|
+
|
|
92
|
+
export interface InjectManifestOptionsComplete
|
|
93
|
+
extends BaseResolved,
|
|
94
|
+
GlobResolved,
|
|
95
|
+
BaseInjectResolved,
|
|
96
|
+
RequiredSwDestResolved,
|
|
97
|
+
RequiredGlobDirectoryResolved,
|
|
98
|
+
InjectResolved {}
|
|
99
|
+
|
|
100
|
+
export interface Hooks {
|
|
101
|
+
beforeBuildServiceWorker?: (options: PluginOptionsComplete) => void | Promise<void>;
|
|
102
|
+
closeBundleOrder?: "pre" | "post" | null;
|
|
103
|
+
configureOptions?: (viteOptions: ResolvedConfig, options: PluginOptions) => void | Promise<void>;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface DevOptions {
|
|
107
|
+
/**
|
|
108
|
+
* Whether the service worker should be bundled in development mode.
|
|
109
|
+
*
|
|
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
|
+
* @default true
|
|
116
|
+
*/
|
|
117
|
+
bundle?: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Whether the service worker should be minified in development mode.
|
|
120
|
+
*
|
|
121
|
+
* @default false
|
|
122
|
+
*/
|
|
123
|
+
minify?: BuildOptions["minify"];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface PluginOptions extends InjectManifestOptions {}
|
|
127
|
+
|
|
128
|
+
export interface PluginOptionsComplete extends InjectResolved {
|
|
129
|
+
injectManifest: Omit<InjectManifestOptionsComplete, keyof InjectResolved>;
|
|
130
|
+
}
|
|
131
|
+
|
|
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
|
+
export interface SerwistViteApi {
|
|
148
|
+
/**
|
|
149
|
+
* Whether the plugin is disabled.
|
|
150
|
+
*/
|
|
151
|
+
disabled: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Extends the precache manifest.
|
|
154
|
+
* @param fn
|
|
155
|
+
*/
|
|
156
|
+
extendManifestEntries(fn: ExtendManifestEntriesHook): void;
|
|
157
|
+
/*
|
|
158
|
+
* Generates the service worker.
|
|
159
|
+
*/
|
|
160
|
+
generateSW(): Promise<void>;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export type ExtendManifestEntriesHook = (manifestEntries: (string | ManifestEntry)[]) => (string | ManifestEntry)[] | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SerwistConfigError, validationErrorMap } from "@serwist/build/schema";
|
|
2
|
+
import type { InjectManifestOptionsComplete } from "./types.js";
|
|
3
|
+
|
|
4
|
+
export const validateInjectManifestOptions = async (input: unknown): Promise<InjectManifestOptionsComplete> => {
|
|
5
|
+
const result = await (await import("./schema.js")).injectManifestOptions.spa(input, { errorMap: validationErrorMap });
|
|
6
|
+
if (!result.success) {
|
|
7
|
+
throw new SerwistConfigError({ moduleName: "@serwist/vite", message: JSON.stringify(result.error.format(), null, 2) });
|
|
8
|
+
}
|
|
9
|
+
return result.data;
|
|
10
|
+
};
|
package/src/plugins/build.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
2
|
|
|
3
|
-
import type { SerwistViteContext } from "../context.js";
|
|
4
|
-
import type { SerwistViteApi } from "../types.js";
|
|
3
|
+
import type { SerwistViteContext } from "../lib/context.js";
|
|
4
|
+
import type { SerwistViteApi } from "../lib/types.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal build plugin used by `@serwist/vite`.
|
package/src/plugins/dev.ts
CHANGED
|
@@ -3,9 +3,9 @@ import path from "node:path";
|
|
|
3
3
|
|
|
4
4
|
import { type Plugin, normalizePath } from "vite";
|
|
5
5
|
|
|
6
|
-
import type { SerwistViteContext } from "../context.js";
|
|
7
|
-
import type { SerwistViteApi } from "../types.js";
|
|
8
|
-
import { toFs } from "../utils.js";
|
|
6
|
+
import type { SerwistViteContext } from "../lib/context.js";
|
|
7
|
+
import type { SerwistViteApi } from "../lib/types.js";
|
|
8
|
+
import { toFs } from "../lib/utils.js";
|
|
9
9
|
|
|
10
10
|
// This plugin handles the service worker in two ways:
|
|
11
11
|
// - If `devOptions.bundle` is enabled, hook a middleware that bundles the service worker
|
package/src/plugins/main.ts
CHANGED
|
@@ -2,10 +2,10 @@ 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 "../constants.js";
|
|
6
|
-
import type { SerwistViteContext } from "../context.js";
|
|
7
|
-
import { resolveOptions } from "../options.js";
|
|
8
|
-
import type { SerwistViteApi } from "../types.js";
|
|
5
|
+
import { INTERNAL_SERWIST_VIRTUAL, RESOLVED_INTERNAL_SERWIST_VIRTUAL } from "../lib/constants.js";
|
|
6
|
+
import type { SerwistViteContext } from "../lib/context.js";
|
|
7
|
+
import { resolveOptions } from "../lib/options.js";
|
|
8
|
+
import type { SerwistViteApi } from "../lib/types.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Internal plugin used by `@serwist/vite`.
|
|
@@ -38,7 +38,7 @@ export const mainPlugin = (ctx: SerwistViteContext, api: SerwistViteApi) => {
|
|
|
38
38
|
},
|
|
39
39
|
load(id) {
|
|
40
40
|
if (id === RESOLVED_INTERNAL_SERWIST_VIRTUAL) {
|
|
41
|
-
return `export const swUrl = "${path.posix.join(ctx.options.
|
|
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}";`;
|
|
44
44
|
}
|
package/src/rollup.js
CHANGED
|
@@ -11,12 +11,13 @@ export default getRollupOptions({
|
|
|
11
11
|
index: "src/index.ts",
|
|
12
12
|
"index.browser": "src/index.browser.ts",
|
|
13
13
|
"index.worker": "src/index.worker.ts",
|
|
14
|
+
"index.schema": "src/index.schema.ts",
|
|
14
15
|
},
|
|
15
16
|
output: {
|
|
16
17
|
dir: "dist",
|
|
17
|
-
format: "esm",
|
|
18
18
|
entryFileNames: "[name].js",
|
|
19
|
-
chunkFileNames: "[name].js",
|
|
19
|
+
chunkFileNames: "chunks/[name].js",
|
|
20
|
+
format: "esm",
|
|
20
21
|
},
|
|
21
22
|
external: ["virtual:internal-serwist"],
|
|
22
23
|
},
|
package/dist/api.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGvD,OAAO,KAAK,EAA6B,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5E,eAAO,MAAM,SAAS,QAAS,kBAAkB,KAAG,cA8BnD,CAAC"}
|
package/dist/assets.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { ResolvedConfig } from "vite";
|
|
2
|
-
import type { ResolvedPluginOptions } from "./types.js";
|
|
3
|
-
export declare const configureStaticAssets: (resolvedPluginOptions: ResolvedPluginOptions, viteConfig: ResolvedConfig) => Promise<void>;
|
|
4
|
-
//# sourceMappingURL=assets.d.ts.map
|
package/dist/assets.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAE3C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AA+BxD,eAAO,MAAM,qBAAqB,0BAAiC,qBAAqB,cAAc,cAAc,kBAoCnH,CAAC"}
|
package/dist/constants.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,6BAA6B,CAAC;AACnE,eAAO,MAAM,iCAAiC,+BAAkC,CAAC"}
|
package/dist/context.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAE3C,OAAO,KAAK,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEvE,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAE3C,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,UAAU,EAAE,cAAc,CAAC;IAC3B;;OAEG;IACH,WAAW,EAAE,aAAa,CAAC;IAC3B;;;;;OAKG;IACH,OAAO,EAAE,qBAAqB,CAAC;IAC/B,iBAAiB,EAAE,OAAO,CAAC;IAC3B;;;;OAIG;IACH,cAAc,EAAE,OAAO,CAAC;IACxB,8CAA8C;IAC9C,SAAS,EAAE,qBAAqB,GAAG,SAAS,CAAC;CAC9C;AAED,eAAO,MAAM,aAAa,gBAAiB,aAAa,aAAa,qBAAqB,GAAG,SAAS,KAAG,kBASxG,CAAC"}
|
package/dist/log.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAI3C,eAAO,MAAM,gBAAgB,gBAAiB,KAAK,WAAW,EAAE,OAAO,GAAG,MAAM,GAAG,UAAU,CAAC,eAAe,cAAc,SAkB1H,CAAC"}
|
package/dist/modules.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"modules.d.ts","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAEpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD,eAAO,MAAM,gBAAgB,QAAa,QAAQ,mBAAmB,CASpE,CAAC;AAEF,UAAU,WAAY,SAAQ,YAAY,CAAC,iBAAiB;IAC1D,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,eAAO,MAAM,cAAc,WAAkB,aAAa,yBAAyB,KAAG,QAAQ,WAAW,CAYxG,CAAC;AAEF,eAAO,MAAM,qBAAqB,QAAe,kBAAkB,qCAwIlE,CAAC"}
|
package/dist/options.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { ResolvedConfig } from "vite";
|
|
2
|
-
import type { PluginOptions, ResolvedPluginOptions } from "./types.js";
|
|
3
|
-
export declare const resolveOptions: (options: PluginOptions, viteConfig: ResolvedConfig) => Promise<ResolvedPluginOptions>;
|
|
4
|
-
//# sourceMappingURL=options.d.ts.map
|
package/dist/options.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAI3C,OAAO,KAAK,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGvE,eAAO,MAAM,cAAc,YAAmB,aAAa,cAAc,cAAc,KAAG,QAAQ,qBAAqB,CA+EtH,CAAC"}
|