@cloudflare/vite-plugin 2.0.0-beta.v.8 → 2.0.0-beta.v.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.
- package/README.md +34 -0
- package/dist/index.d.mts +13 -4
- package/dist/index.mjs +295 -395
- package/dist/{package-Do6Tqzt_.mjs → package--jIwlDD7.mjs} +1 -2
- package/package.json +11 -12
package/README.md
CHANGED
|
@@ -18,6 +18,40 @@ export default defineConfig({
|
|
|
18
18
|
|
|
19
19
|
Full documentation can be found [here](https://developers.cloudflare.com/workers/vite-plugin/).
|
|
20
20
|
|
|
21
|
+
## Programmatic configuration
|
|
22
|
+
|
|
23
|
+
The `config` option accepts a customizer with the signature
|
|
24
|
+
`(loadedConfig: ParsedInputConfigWithWorker) => ParsedInputConfigWithWorker`. It receives the parsed
|
|
25
|
+
`cloudflare.config.ts` configuration, or a default Worker configuration when no
|
|
26
|
+
file exists, and can customize account settings, Containers, and the entry Worker.
|
|
27
|
+
The loaded and returned configurations must include a Worker, even for assets-only projects.
|
|
28
|
+
|
|
29
|
+
Return a new configuration object, spreading any existing fields you want to
|
|
30
|
+
preserve. Nested objects and arrays are replaced rather than merged:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { cloudflare } from "@cloudflare/vite-plugin";
|
|
34
|
+
|
|
35
|
+
cloudflare({
|
|
36
|
+
config(loadedConfig) {
|
|
37
|
+
return {
|
|
38
|
+
...loadedConfig,
|
|
39
|
+
worker: {
|
|
40
|
+
...loadedConfig.worker,
|
|
41
|
+
env: {
|
|
42
|
+
...loadedConfig.worker.env,
|
|
43
|
+
FRAMEWORK_NAME: { type: "text", value: "my-framework" },
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The customized configuration is recorded in the build output. Preview and
|
|
52
|
+
deployment from that output use the recorded configuration. Generated types
|
|
53
|
+
continue to describe `cloudflare.config.ts`.
|
|
54
|
+
|
|
21
55
|
## Features
|
|
22
56
|
|
|
23
57
|
- Uses the Vite [Environment API](https://vite.dev/guide/api-environment) to integrate Vite with the Workers runtime
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import * as vite from "vite";
|
|
2
|
-
import { InputWorkerConfig, ParsedInputWorkerConfig, WorkerConfig } from "@cloudflare/config";
|
|
2
|
+
import { InputWorkerConfig, ParsedInputConfig, ParsedInputWorkerConfig, WorkerConfig } from "@cloudflare/config";
|
|
3
3
|
import { CompatDate } from "@cloudflare/workers-utils";
|
|
4
4
|
|
|
5
5
|
//#region src/plugin-config.d.ts
|
|
6
6
|
|
|
7
|
+
/** Parsed configuration with the entry Worker required by the Vite plugin. */
|
|
8
|
+
type ParsedInputConfigWithWorker = Omit<ParsedInputConfig, "worker"> & {
|
|
9
|
+
worker: ParsedInputWorkerConfig;
|
|
10
|
+
};
|
|
7
11
|
type PersistState = boolean | {
|
|
8
12
|
path: string;
|
|
9
13
|
};
|
|
@@ -26,7 +30,6 @@ interface BaseWorkerOptions {
|
|
|
26
30
|
*/
|
|
27
31
|
type DevOnly = boolean | (() => boolean);
|
|
28
32
|
interface EntryWorkerOptions extends BaseWorkerOptions {
|
|
29
|
-
config?: EntryWorkerConfigCustomizer;
|
|
30
33
|
/**
|
|
31
34
|
* Whether the entry Worker should be omitted from the production build.
|
|
32
35
|
* Can be a boolean or a function that returns a boolean. The function is
|
|
@@ -64,11 +67,17 @@ interface Experimental {
|
|
|
64
67
|
/** Experimental support for handling the _headers and _redirects files during Vite dev mode. */
|
|
65
68
|
headersAndRedirectsDevModeSupport?: boolean;
|
|
66
69
|
}
|
|
67
|
-
type EntryWorkerConfigCustomizer = Partial<ParsedInputWorkerConfig> | ((config: ParsedInputWorkerConfig) => Partial<ParsedInputWorkerConfig> | void);
|
|
68
70
|
type WorkerConfigProvider = InputWorkerConfig | ((options: {
|
|
69
71
|
entryWorkerConfig: ParsedInputWorkerConfig;
|
|
70
72
|
}) => InputWorkerConfig);
|
|
71
73
|
interface PluginConfig extends EntryWorkerOptions {
|
|
74
|
+
/**
|
|
75
|
+
* Customize the loaded configuration before development or building.
|
|
76
|
+
* The loaded configuration always includes an entry Worker.
|
|
77
|
+
* Return a new configuration object including an entry Worker, copying any settings to preserve.
|
|
78
|
+
* Preview uses the configuration recorded in the build output.
|
|
79
|
+
*/
|
|
80
|
+
config?: (loadedConfig: ParsedInputConfigWithWorker) => ParsedInputConfigWithWorker;
|
|
72
81
|
auxiliaryWorkers?: AuxiliaryWorkerOptions[];
|
|
73
82
|
/** Configuration for a dedicated prerender Worker. */
|
|
74
83
|
prerenderWorker?: PrerenderWorkerOptions;
|
|
@@ -111,4 +120,4 @@ declare function getLocalWorkerdCompatibilityDate(_options?: {
|
|
|
111
120
|
*/
|
|
112
121
|
declare function cloudflare(pluginConfig?: PluginConfig): vite.Plugin[];
|
|
113
122
|
//#endregion
|
|
114
|
-
export { type PluginConfig, type WorkerConfig, cloudflare, getLocalWorkerdCompatibilityDate };
|
|
123
|
+
export { type ParsedInputConfigWithWorker, type PluginConfig, type WorkerConfig, cloudflare, getLocalWorkerdCompatibilityDate };
|