@solidjs/vite-plugin 3.0.0-next.27
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 +711 -0
- package/boundary-modules.d.ts +15 -0
- package/dist/cjs/index.cjs +3412 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/index.mjs +3386 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/cypress/e2e/examples.cy.d.ts +0 -0
- package/dist/types/cypress/support/e2e.d.ts +0 -0
- package/dist/types/src/boundary-modules.d.ts +18 -0
- package/dist/types/src/dev-manifest.d.ts +128 -0
- package/dist/types/src/environment.d.ts +13 -0
- package/dist/types/src/http.d.ts +10 -0
- package/dist/types/src/index.d.ts +220 -0
- package/dist/types/src/server-functions/compile.d.ts +38 -0
- package/dist/types/src/server-functions/index.d.ts +145 -0
- package/dist/types/src/server-functions/xxhash32.d.ts +5 -0
- package/dist/types/src/ssr/index.d.ts +162 -0
- package/dist/types/src/start-env.d.ts +10 -0
- package/package.json +98 -0
- package/virtual-solid-manifest.d.ts +52 -0
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* `server-only` and `client-only` marker modules: importing `server-only`
|
|
4
|
+
* from a module bundled for the client fails the build at resolve time with
|
|
5
|
+
* a descriptive error (and vice versa for `client-only`); in the allowed
|
|
6
|
+
* environment the marker resolves to an empty module.
|
|
7
|
+
*
|
|
8
|
+
* Server-only code pulled into a client bundle otherwise ships silently and
|
|
9
|
+
* crashes at runtime (in hydrating apps, typically as a cryptic hydration
|
|
10
|
+
* failure far from the real cause) — the marker turns that into a build
|
|
11
|
+
* error naming the importer.
|
|
12
|
+
*
|
|
13
|
+
* Always on (`enforce: 'pre'`), so the bare specifiers are claimed by this
|
|
14
|
+
* plugin even when React's `server-only`/`client-only` npm packages are
|
|
15
|
+
* installed — the environment semantics are the same, and claiming them
|
|
16
|
+
* keeps the behavior deterministic and the errors identifiable as ours.
|
|
17
|
+
*/
|
|
18
|
+
export declare function boundaryModules(): Plugin;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { DevEnvironment, ViteDevServer } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Dev-mode asset resolution: the `virtual:solid-manifest` module exports a
|
|
4
|
+
* resolver function in dev (instead of the static object a build produces),
|
|
5
|
+
* and the runtime installs it as `context.resolveAssets` verbatim. When
|
|
6
|
+
* server-side `lazy()` resolves a module key, the resolver walks the SSR
|
|
7
|
+
* environment's live module graph collecting transitively imported CSS and
|
|
8
|
+
* answers with inline-style descriptors — SSR'd `<style data-vite-dev-id>`
|
|
9
|
+
* tags that Vite's HMR client adopts on startup, so dev CSS is styled from
|
|
10
|
+
* the first streamed byte without fighting Vite's own style injection.
|
|
11
|
+
*
|
|
12
|
+
* The walk design follows SolidStart's collect-styles (by @katywings): crawl
|
|
13
|
+
* `transformResult.deps` on the SSR environment (the client environment's
|
|
14
|
+
* transform results don't list CSS deps), skipping dynamic imports since
|
|
15
|
+
* dynamically imported modules register their own styles when they render.
|
|
16
|
+
*/
|
|
17
|
+
export type DevStyleDescriptor = {
|
|
18
|
+
id: string;
|
|
19
|
+
content: string;
|
|
20
|
+
attrs?: Record<string, string>;
|
|
21
|
+
};
|
|
22
|
+
export type DevStyleSource = {
|
|
23
|
+
id: string;
|
|
24
|
+
url: string;
|
|
25
|
+
};
|
|
26
|
+
export type ResolvedAssets = {
|
|
27
|
+
js: string[];
|
|
28
|
+
css: (string | DevStyleDescriptor)[];
|
|
29
|
+
};
|
|
30
|
+
export type DevAssetResolver = {
|
|
31
|
+
/**
|
|
32
|
+
* Answers synchronously (a plain object) once the key's assets are known.
|
|
33
|
+
* The sync answer is load-bearing for SSR convergence: the runtime retries
|
|
34
|
+
* a suspended render pass by re-creating the lazy component, which
|
|
35
|
+
* re-requests its assets — if every answer is a fresh pending promise the
|
|
36
|
+
* pass suspends again on a promise that did not exist when the retry
|
|
37
|
+
* began, and never converges (see `createDevAssetResolver`).
|
|
38
|
+
*/
|
|
39
|
+
resolve: (key: string) => ResolvedAssets | null | Promise<ResolvedAssets | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Synchronous fast path used by sync consumers (a lazy component's
|
|
42
|
+
* `moduleUrl` getter for islands): the module's dev URL is knowable
|
|
43
|
+
* without the async CSS graph walk.
|
|
44
|
+
*/
|
|
45
|
+
resolveSync: (key: string) => ResolvedAssets;
|
|
46
|
+
};
|
|
47
|
+
export declare const DEV_MANIFEST_REGISTRY_KEY = "@solidjs/vite-plugin:dev-manifest";
|
|
48
|
+
export declare function registerDevAssetResolver(root: string, resolver: DevAssetResolver): void;
|
|
49
|
+
/**
|
|
50
|
+
* HTTP bridge endpoint for isolated SSR runners. Hosts that evaluate server
|
|
51
|
+
* modules outside the Vite process (nitro's dev worker, workerd via
|
|
52
|
+
* @cloudflare/vite-plugin) can't see the `globalThis` registry, so the dev
|
|
53
|
+
* server itself serves asset resolution: `GET
|
|
54
|
+
* /@solidjs/vite-plugin/dev-manifest?key=<module key>` answers with the
|
|
55
|
+
* resolver's `ResolvedAssets` JSON (`null` when the key can't be resolved).
|
|
56
|
+
* The dev flavor of `virtual:solid-manifest` falls back to fetching it when
|
|
57
|
+
* the registry has no entry for the root — in-process consumers hit the
|
|
58
|
+
* registry and never touch HTTP.
|
|
59
|
+
*/
|
|
60
|
+
export declare const DEV_MANIFEST_ENDPOINT = "/@solidjs/vite-plugin/dev-manifest";
|
|
61
|
+
export declare function installDevManifestBridge(server: ViteDevServer): void;
|
|
62
|
+
/**
|
|
63
|
+
* The absolute URL isolated runners should fetch the bridge from, baked into
|
|
64
|
+
* the dev flavor of `virtual:solid-manifest` when its code is generated.
|
|
65
|
+
* Generation happens while serving an SSR request, so the server is already
|
|
66
|
+
* listening and `resolvedUrls` carries the real origin (a config-time define
|
|
67
|
+
* could only guess the port). Middleware-mode servers have no origin of
|
|
68
|
+
* their own to advertise — returns null there, and the manifest module keeps
|
|
69
|
+
* the js-only fallback (in-process registry hits are unaffected either way).
|
|
70
|
+
*/
|
|
71
|
+
export declare function devManifestBridgeUrl(server: ViteDevServer): string | null;
|
|
72
|
+
/**
|
|
73
|
+
* Inline dev script reconciling SSR'd style tags with Vite's HMR client.
|
|
74
|
+
* Frameworks that server-render whole documents should inline this in dev,
|
|
75
|
+
* in `<head>` before any module script. It does two things, via a
|
|
76
|
+
* MutationObserver so styles appended by streamed boundaries are handled as
|
|
77
|
+
* they arrive (Vite's client seeds its stylesheet registry from the DOM only
|
|
78
|
+
* once, when its module evaluates):
|
|
79
|
+
*
|
|
80
|
+
* - Rewrites serialized virtual-module ids (`/@id/__x00__…`) back to Vite's
|
|
81
|
+
* null-byte form so seeding matches (a raw `\0` can't survive HTML).
|
|
82
|
+
* - Dedupes twins: a style tag that streams in after Vite's client has
|
|
83
|
+
* seeded is missed by the scan, so the CSS module injects its own copy
|
|
84
|
+
* client-side. Whenever two style tags share a `data-vite-dev-id`, the
|
|
85
|
+
* SSR'd one (marked `data-asset`) is removed in favor of the Vite-owned
|
|
86
|
+
* one, which is the tag HMR updates.
|
|
87
|
+
*
|
|
88
|
+
* Observation is two-phase to stay cheap: a document-wide subtree observer
|
|
89
|
+
* only for the streaming window (SSR tags can only arrive while the parser
|
|
90
|
+
* is consuming the stream; DOMContentLoaded marks its end), then a
|
|
91
|
+
* childList-only observer on `document.head` for the page lifetime — Vite
|
|
92
|
+
* injects twins into the head during hydration, which continues past
|
|
93
|
+
* DOMContentLoaded, and a non-subtree head observer never fires on app DOM
|
|
94
|
+
* churn, only on head insertions.
|
|
95
|
+
*
|
|
96
|
+
* Descends from SolidStart's PatchVirtualDevStyles (by @katywings); this
|
|
97
|
+
* belongs in Vite itself eventually.
|
|
98
|
+
*/
|
|
99
|
+
export declare const devStylePatch: string;
|
|
100
|
+
/** Discovers ambient CSS in an entry graph without choosing how it is transported. */
|
|
101
|
+
export declare function collectDevStyleSources(env: DevEnvironment, files: string[], onFile?: (file: string) => void): Promise<DevStyleSource[]>;
|
|
102
|
+
/**
|
|
103
|
+
* Walks the SSR module graph from `files` (root-relative or absolute) and
|
|
104
|
+
* returns inline-style descriptors for every transitively imported CSS
|
|
105
|
+
* module — the same shape the dev asset resolver answers with for lazy
|
|
106
|
+
* modules. Used by SSR start mode's dev middleware to inline the root entry's
|
|
107
|
+
* CSS into `<head>` so server-painted content is styled from the first byte
|
|
108
|
+
* (no FOUC while waiting for Vite's client-side style injection).
|
|
109
|
+
*/
|
|
110
|
+
export declare function collectDevStyles(server: ViteDevServer, files: string[]): Promise<DevStyleDescriptor[]>;
|
|
111
|
+
/**
|
|
112
|
+
* Serializes a dev style descriptor to the exact tag shape the SSR runtime
|
|
113
|
+
* emits for lazy-registered assets (`data-asset` marks the SSR'd copy so
|
|
114
|
+
* `devStylePatch` knows which twin to drop when Vite's client injects its
|
|
115
|
+
* own), so the dedup story is identical for entry styles and lazy styles.
|
|
116
|
+
*/
|
|
117
|
+
export declare function renderDevStyleTag(desc: DevStyleDescriptor): string;
|
|
118
|
+
/**
|
|
119
|
+
* Browser URL for a lazy module's dev asset key (a project-root-relative
|
|
120
|
+
* path, query included when the module identity carries one). Vite only
|
|
121
|
+
* serves module URLs under the configured `base`, so it is always applied;
|
|
122
|
+
* root-external keys (`../…`, e.g. sibling workspace packages) can't be
|
|
123
|
+
* expressed as root-relative URLs at all — they get Vite's `/@fs/` form on
|
|
124
|
+
* the resolved absolute path instead. Mirrored by the generated fallback in
|
|
125
|
+
* `devManifestCode` (src/index.ts) — keep the two in sync.
|
|
126
|
+
*/
|
|
127
|
+
export declare function devModuleUrl(root: string, base: string, key: string): string;
|
|
128
|
+
export declare function createDevAssetResolver(server: ViteDevServer): DevAssetResolver;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-instance-safe stand-in for vite's `isRunnableDevEnvironment`.
|
|
3
|
+
*
|
|
4
|
+
* Vite's helper is an `instanceof RunnableDevEnvironment` check against the
|
|
5
|
+
* class of whichever `vite` module the CALLER imported. When this plugin is
|
|
6
|
+
* consumed through a workspace/`link:` install, its own `vite` import can
|
|
7
|
+
* resolve to a different physical copy than the one running the dev server —
|
|
8
|
+
* and then the `instanceof` is false for every environment, silently standing
|
|
9
|
+
* the SSR/dev middlewares down. The `runner` accessor is the type's defining
|
|
10
|
+
* member (`RunnableDevEnvironment` is exactly "a DevEnvironment with a
|
|
11
|
+
* runner"), so presence-check it instead of trusting class identity.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isRunnableEnvironment(environment: unknown): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
/**
|
|
3
|
+
* `urlPath` overrides `req.url` when the middleware needs to dispatch a
|
|
4
|
+
* different URL than the one node saw — the dev middlewares use it to
|
|
5
|
+
* restore the configured Vite `base` that the dev/preview base middleware
|
|
6
|
+
* stripped, so the handler always sees production-shaped URLs.
|
|
7
|
+
*/
|
|
8
|
+
export declare function webRequestFromNode(req: IncomingMessage, urlPath?: string): Request;
|
|
9
|
+
export declare function sendWebResponse(res: ServerResponse, response: Response): Promise<void>;
|
|
10
|
+
export declare function joinBase(base: string, pathname: string): string;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import * as babel from '@babel/core';
|
|
2
|
+
import type { TransformOptions as JsxCompilerOptions } from '@dom-expressions/compiler';
|
|
3
|
+
import { serverFunctions, type ServerFunctionsOptions } from './server-functions/index.js';
|
|
4
|
+
import { type StartOptions } from './ssr/index.js';
|
|
5
|
+
export { devStylePatch } from './dev-manifest.js';
|
|
6
|
+
export { serverFunctions };
|
|
7
|
+
export type { ServerFunctionsOptions };
|
|
8
|
+
export type { ServerFunctionsFilter } from './server-functions/index.js';
|
|
9
|
+
export type { StartOptions };
|
|
10
|
+
import type { FilterPattern, Plugin } from 'vite';
|
|
11
|
+
/** Possible options for the extensions property */
|
|
12
|
+
export interface ExtensionOptions {
|
|
13
|
+
typescript?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export type Compiler = 'babel' | 'native';
|
|
16
|
+
export type SolidOptions = Omit<JsxCompilerOptions, 'filename' | 'sourceMap'>;
|
|
17
|
+
/** Configuration options for @solidjs/vite-plugin. */
|
|
18
|
+
export interface Options {
|
|
19
|
+
/**
|
|
20
|
+
* A [picomatch](https://github.com/micromatch/picomatch) pattern, or array of patterns, which specifies the files
|
|
21
|
+
* the plugin should operate on. Relative patterns are resolved against the
|
|
22
|
+
* Vite root, not the invocation directory.
|
|
23
|
+
*/
|
|
24
|
+
include?: FilterPattern;
|
|
25
|
+
/**
|
|
26
|
+
* A [picomatch](https://github.com/micromatch/picomatch) pattern, or array of patterns, which specifies the files
|
|
27
|
+
* to be ignored by the plugin. Relative patterns are resolved against the
|
|
28
|
+
* Vite root, not the invocation directory.
|
|
29
|
+
*/
|
|
30
|
+
exclude?: FilterPattern;
|
|
31
|
+
/**
|
|
32
|
+
* This will inject solid-js/dev in place of solid-js in dev mode. Has no
|
|
33
|
+
* effect in prod. If set to `false`, it won't inject it in dev. This is
|
|
34
|
+
* useful for extra logs and debugging.
|
|
35
|
+
*
|
|
36
|
+
* @default true
|
|
37
|
+
*/
|
|
38
|
+
dev?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Whether the app is server-rendered — one meaning everywhere.
|
|
41
|
+
*
|
|
42
|
+
* Without {@link start}: the legacy transform-only flag, unchanged.
|
|
43
|
+
* `true` enables the SSR transforms (hydratable client code, SSR server
|
|
44
|
+
* code) — you provide the entries and the server yourself.
|
|
45
|
+
*
|
|
46
|
+
* With {@link start}: selects the start mode. `true` is SSR start mode
|
|
47
|
+
* (per-request streaming render + hydration); `false`/omitted is client
|
|
48
|
+
* mode (a static document shell + client-side `render()`). Flipping a
|
|
49
|
+
* start-mode project between SPA and SSR is toggling this one boolean.
|
|
50
|
+
*
|
|
51
|
+
* The flag describes the app's initial document, not the internal
|
|
52
|
+
* pipelines — client mode still compiles the document shell through the
|
|
53
|
+
* SSR transforms to serve/prerender it.
|
|
54
|
+
*
|
|
55
|
+
* Objects are no longer accepted: start-mode options moved to {@link start}
|
|
56
|
+
* (`ssr: { ... }` from 3.0.0-next.23 and earlier becomes
|
|
57
|
+
* `start: { ... }, ssr: true`).
|
|
58
|
+
*
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
ssr?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Start mode — Start as a mode of the plugin: it owns entries, dev
|
|
64
|
+
* serving, and the build — no index.html, no mount file, no server
|
|
65
|
+
* wiring. `start: true` is the zero-config spelling, sugar for the empty
|
|
66
|
+
* options bag `start: {}` (both mean the identical start mode with
|
|
67
|
+
* defaults; `false`/absent is off). Conventions (shared by both modes,
|
|
68
|
+
* so projects flip between them by toggling {@link ssr}): `src/App.*`
|
|
69
|
+
* (or `start.app`) is the root component; `src/Document.*` (or
|
|
70
|
+
* `start.document`) is the optional document shell; authored
|
|
71
|
+
* `src/entry-server.*` / `src/entry-client.*` (or `start.entryServer` /
|
|
72
|
+
* `start.entryClient`) replace the generated entries.
|
|
73
|
+
*
|
|
74
|
+
* With `ssr: true` — SSR start mode:
|
|
75
|
+
*
|
|
76
|
+
* - Dev: a middleware on the Vite dev server streams the rendered app for
|
|
77
|
+
* HTML-accepting GET requests — `vite` just works, no server file.
|
|
78
|
+
* - Build: a plain `vite build` produces both bundles (client to
|
|
79
|
+
* `dist/client`, server to `dist/server` via the environments/builder
|
|
80
|
+
* API). The server bundle's entry is `virtual:solid-ssr-handler`, whose
|
|
81
|
+
* `handleRequest(request)` export maps a web `Request` to a streamed
|
|
82
|
+
* `Response`; its default `{ fetch(request) }` export provides the same
|
|
83
|
+
* handler in the Fetchable shape used by deployment integrations.
|
|
84
|
+
* The normal `ssr` environment exposes it as the `index` service entry
|
|
85
|
+
* so provider Vite plugins can supply the runtime and build orchestration.
|
|
86
|
+
* - With `serverFunctions` also enabled, the prod handler serves the
|
|
87
|
+
* server-function endpoint too (in dev the server-function middleware
|
|
88
|
+
* already runs first).
|
|
89
|
+
*
|
|
90
|
+
* Without `ssr: true` — client mode:
|
|
91
|
+
*
|
|
92
|
+
* - Dev: every HTML-accepting GET streams the rendered document shell
|
|
93
|
+
* (without the app — history-fallback semantics); the generated client
|
|
94
|
+
* entry `render()`s the app into it.
|
|
95
|
+
* - Build: `vite build` emits a static `dist/client` — the shell is
|
|
96
|
+
* prerendered once through the built handler into
|
|
97
|
+
* `dist/client/index.html` with the hashed entry script and CSS links —
|
|
98
|
+
* deployable to any static host. No server bundle remains unless
|
|
99
|
+
* `serverFunctions` is enabled, in which case `dist/server` is kept and
|
|
100
|
+
* its `handleRequest` serves the endpoint (pages stay static).
|
|
101
|
+
* - Client code stays non-hydratable (`generate: 'dom'`), exactly like a
|
|
102
|
+
* plain SPA; server-only options (`entryServer`, `external`) are inert.
|
|
103
|
+
* - `vite preview` serves the static build with history fallback (and
|
|
104
|
+
* dispatches the server-function endpoint through the kept handler).
|
|
105
|
+
*
|
|
106
|
+
* @default undefined
|
|
107
|
+
*/
|
|
108
|
+
start?: boolean | StartOptions;
|
|
109
|
+
/**
|
|
110
|
+
* JSX compiler backend to use. The default `"native"` compiles through
|
|
111
|
+
* `@dom-expressions/compiler`; `"babel"` is the escape hatch running
|
|
112
|
+
* `babel-preset-solid` instead — if native output ever differs from your
|
|
113
|
+
* expectations, set `compiler: "babel"` and file an issue (the behavioral
|
|
114
|
+
* diff between the modes is the bug report). Platforms without a prebuilt
|
|
115
|
+
* native binary (e.g. StackBlitz WebContainers) automatically use the wasm
|
|
116
|
+
* fallback; the compiler package itself is required in every mode.
|
|
117
|
+
*
|
|
118
|
+
* @default "native"
|
|
119
|
+
*/
|
|
120
|
+
compiler?: Compiler;
|
|
121
|
+
/**
|
|
122
|
+
* This will inject HMR runtime in dev mode. Has no effect in prod. If
|
|
123
|
+
* set to `false`, it won't inject the runtime in dev.
|
|
124
|
+
*
|
|
125
|
+
* @default true
|
|
126
|
+
* @deprecated use `refresh` instead
|
|
127
|
+
*/
|
|
128
|
+
hot?: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* This registers additional extensions that should be processed by
|
|
131
|
+
* @solidjs/vite-plugin.
|
|
132
|
+
*
|
|
133
|
+
* @default undefined
|
|
134
|
+
*/
|
|
135
|
+
extensions?: (string | [string, ExtensionOptions])[];
|
|
136
|
+
/**
|
|
137
|
+
* Pass any additional babel transform options. They will be merged with
|
|
138
|
+
* the transformations required by Solid.
|
|
139
|
+
*
|
|
140
|
+
* Note: with `compiler: "native"` the plugin is normally fully Babel-free
|
|
141
|
+
* (native lazy/refresh/JSX passes). Supplying custom babel options
|
|
142
|
+
* reintroduces a Babel support pass ahead of the native JSX transform to
|
|
143
|
+
* host them.
|
|
144
|
+
*
|
|
145
|
+
* @default {}
|
|
146
|
+
*/
|
|
147
|
+
babel?: babel.TransformOptions | ((source: string, id: string, ssr: boolean) => babel.TransformOptions) | ((source: string, id: string, ssr: boolean) => Promise<babel.TransformOptions>);
|
|
148
|
+
/**
|
|
149
|
+
* Pass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).
|
|
150
|
+
* They will be merged with the defaults sets by [babel-preset-solid](https://github.com/solidjs/solid/blob/main/packages/babel-preset-solid/index.js#L8-L25).
|
|
151
|
+
*
|
|
152
|
+
* @default {}
|
|
153
|
+
*/
|
|
154
|
+
solid?: SolidOptions;
|
|
155
|
+
/**
|
|
156
|
+
* Enable `"use server"` server function compilation (experimental). Pass
|
|
157
|
+
* `true` for the defaults (runtime from @solidjs/web/server-functions) or
|
|
158
|
+
* an options object to customize. The directive transform sub-plugins are
|
|
159
|
+
* emitted ahead of the JSX transform in the returned plugin array.
|
|
160
|
+
*
|
|
161
|
+
* Zero-config setup: in dev, a middleware on the Vite server handles the
|
|
162
|
+
* endpoint (default `/_server`, joined with `base`) end to end — no
|
|
163
|
+
* server-function code needed in the server entry. For production SSR
|
|
164
|
+
* builds, import `virtual:solid-server-function-handler` in the server
|
|
165
|
+
* entry and mount its `handleServerFunctionRequest(request)` export on the
|
|
166
|
+
* endpoint; it eagerly imports every module containing server functions so
|
|
167
|
+
* registrations survive tree-shaking.
|
|
168
|
+
*
|
|
169
|
+
* Hosts whose own server environment should own endpoint dispatch in dev
|
|
170
|
+
* (e.g. @cloudflare/vite-plugin, so functions run in workerd with
|
|
171
|
+
* bindings) can keep this option and set
|
|
172
|
+
* `serverFunctions: { devMiddleware: false }` — see
|
|
173
|
+
* {@link ServerFunctionsOptions.devMiddleware}. A server-only module can
|
|
174
|
+
* be pinned into the handler graph for pre-dispatch runtime registration
|
|
175
|
+
* via {@link ServerFunctionsOptions.configure}.
|
|
176
|
+
*
|
|
177
|
+
* Meta-frameworks that need to control plugin ordering themselves (e.g.
|
|
178
|
+
* relative to a file-system router) and dispatch requests through their
|
|
179
|
+
* own server should use the standalone `serverFunctions()` export instead,
|
|
180
|
+
* which never installs the dev middleware.
|
|
181
|
+
*
|
|
182
|
+
* The object form's `components` flag additionally enables server
|
|
183
|
+
* components (experimental) — `"use server"` functions returning a
|
|
184
|
+
* component, served over the same endpoint. They come essentially for
|
|
185
|
+
* free: the endpoint transform is installed automatically, and with
|
|
186
|
+
* SSR start mode (the `start` option with `ssr: true`) and generated entries
|
|
187
|
+
* the document wiring is emitted too. See
|
|
188
|
+
* {@link ServerFunctionsOptions.components}.
|
|
189
|
+
*
|
|
190
|
+
* @default undefined
|
|
191
|
+
*/
|
|
192
|
+
serverFunctions?: boolean | ServerFunctionsOptions;
|
|
193
|
+
/** Options for the solid-refresh HMR transform (dev only). */
|
|
194
|
+
refresh?: RefreshOptions;
|
|
195
|
+
}
|
|
196
|
+
/** Options for the solid-refresh HMR transform (dev only). */
|
|
197
|
+
export interface RefreshOptions {
|
|
198
|
+
/**
|
|
199
|
+
* Disable the refresh transform entirely (equivalent to the deprecated
|
|
200
|
+
* `hot: false`).
|
|
201
|
+
*/
|
|
202
|
+
disabled?: boolean;
|
|
203
|
+
/**
|
|
204
|
+
* Emit per-component `signature`/`dependencies` metadata so edits only
|
|
205
|
+
* remount components whose code actually changed.
|
|
206
|
+
*
|
|
207
|
+
* @default true
|
|
208
|
+
*/
|
|
209
|
+
granular?: boolean;
|
|
210
|
+
}
|
|
211
|
+
export default function solidPlugin(options?: Partial<Options>): Plugin[];
|
|
212
|
+
export type ViteManifest = Record<string, {
|
|
213
|
+
file: string;
|
|
214
|
+
css?: string[];
|
|
215
|
+
isEntry?: boolean;
|
|
216
|
+
isDynamicEntry?: boolean;
|
|
217
|
+
imports?: string[];
|
|
218
|
+
}> & {
|
|
219
|
+
_base?: string;
|
|
220
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface NamedImportDefinition {
|
|
2
|
+
kind: 'named';
|
|
3
|
+
name: string;
|
|
4
|
+
source: string;
|
|
5
|
+
}
|
|
6
|
+
export interface DefaultImportDefinition {
|
|
7
|
+
kind: 'default';
|
|
8
|
+
source: string;
|
|
9
|
+
}
|
|
10
|
+
export type ImportDefinition = DefaultImportDefinition | NamedImportDefinition;
|
|
11
|
+
export interface CompileOptions {
|
|
12
|
+
mode: 'server' | 'client';
|
|
13
|
+
env: 'production' | 'development';
|
|
14
|
+
/** The directive text (default "use server" upstream). */
|
|
15
|
+
directive: string;
|
|
16
|
+
/** Project root; function IDs hash the root-relative path. */
|
|
17
|
+
root: string;
|
|
18
|
+
definitions: {
|
|
19
|
+
register: ImportDefinition;
|
|
20
|
+
create: ImportDefinition;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export interface CompileResult {
|
|
24
|
+
valid: boolean;
|
|
25
|
+
code: string;
|
|
26
|
+
map: string | null;
|
|
27
|
+
functions: import('@dom-expressions/compiler').ServerFunctionMeta[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Runs the directive transform over one module. Function IDs are
|
|
31
|
+
* `hash(relative path)-<counter>`, so the client and server builds of the
|
|
32
|
+
* same checkout agree on every ID (the wire contract) without baking
|
|
33
|
+
* machine-specific absolute paths into the output. A `valid: false` result
|
|
34
|
+
* means the module contained no matching directive and must be left
|
|
35
|
+
* untransformed. Invalid closure captures (a server function referencing a
|
|
36
|
+
* non-top-level binding) throw with the variable name and location.
|
|
37
|
+
*/
|
|
38
|
+
export declare function compile(id: string, code: string, options: CompileOptions): Promise<CompileResult>;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { type FilterPattern, type Plugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Picomatch patterns selecting the modules the directive compiler runs on.
|
|
4
|
+
* Relative patterns (the defaults included) are resolved against the Vite
|
|
5
|
+
* root — not the invocation directory — so running `vite` from outside the
|
|
6
|
+
* project keeps compiling the same files. Absolute patterns are used as-is.
|
|
7
|
+
*
|
|
8
|
+
* @default include "src/**\/*.{jsx,tsx,ts,js,mjs,cjs}", exclude "node_modules/**\/*.{jsx,tsx,ts,js,mjs,cjs}"
|
|
9
|
+
*/
|
|
10
|
+
export interface ServerFunctionsFilter {
|
|
11
|
+
include?: FilterPattern;
|
|
12
|
+
exclude?: FilterPattern;
|
|
13
|
+
}
|
|
14
|
+
export interface ServerFunctionsOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Module specifiers the compiled output imports the runtime from.
|
|
17
|
+
* Each must export `registerServerReference(id, fn)` (server) and
|
|
18
|
+
* `createServerReference(...)` (both sides).
|
|
19
|
+
*
|
|
20
|
+
* @default "@solidjs/web/server-functions" for both (the package's export
|
|
21
|
+
* conditions resolve the client or server half per environment)
|
|
22
|
+
*/
|
|
23
|
+
runtime?: {
|
|
24
|
+
server: string;
|
|
25
|
+
client: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Virtual module id that imports every module containing server functions.
|
|
29
|
+
* Import it for side effects in your server entry so all registrations
|
|
30
|
+
* exist before requests are handled.
|
|
31
|
+
*
|
|
32
|
+
* @default "virtual:solid-server-function-manifest"
|
|
33
|
+
*/
|
|
34
|
+
manifest?: string;
|
|
35
|
+
filter?: ServerFunctionsFilter;
|
|
36
|
+
/**
|
|
37
|
+
* @default "use server"
|
|
38
|
+
*/
|
|
39
|
+
directive?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Path the server-function transport posts to. Joined with Vite `base`.
|
|
42
|
+
* Threaded to the built-in dev middleware, the
|
|
43
|
+
* `virtual:solid-server-function-handler` module, and — whenever the
|
|
44
|
+
* resolved path differs from the runtime default (`/_server`) — runtime
|
|
45
|
+
* `configureServerFunctions{Client,Server}` calls appended to compiled
|
|
46
|
+
* modules (so custom runtimes used with a custom endpoint must export
|
|
47
|
+
* those).
|
|
48
|
+
*
|
|
49
|
+
* @default "/_server"
|
|
50
|
+
*/
|
|
51
|
+
endpoint?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Whether the built-in dev middleware owns the server-function endpoint on
|
|
54
|
+
* the Vite dev server. Only meaningful through the main plugin's
|
|
55
|
+
* `serverFunctions` option (the standalone `serverFunctions()` export
|
|
56
|
+
* never installs the middleware).
|
|
57
|
+
*
|
|
58
|
+
* Set `false` when another plugin's server environment should own
|
|
59
|
+
* dispatch in dev — e.g. @cloudflare/vite-plugin, whose workerd
|
|
60
|
+
* environment carries the bindings (`env`/`ctx`) your server functions
|
|
61
|
+
* need: the middleware executes functions in Vite's node-side SSR
|
|
62
|
+
* environment, so with it installed those requests never reach the
|
|
63
|
+
* worker. With the middleware off, everything else keeps working —
|
|
64
|
+
* compilation, the manifest and handler virtual modules — and endpoint
|
|
65
|
+
* requests fall through to whatever the host serves; the host loads
|
|
66
|
+
* `virtual:solid-server-function-handler` itself and dispatches through
|
|
67
|
+
* its `handleServerFunctionRequest` export, exactly like production.
|
|
68
|
+
* Functions referenced only by client code register on demand through
|
|
69
|
+
* the middleware in dev, so a host owning dispatch should side-effect
|
|
70
|
+
* import the manifest module in its server entry to cover them.
|
|
71
|
+
*
|
|
72
|
+
* When a provider owns the dev server's `ssr` environment (it isn't
|
|
73
|
+
* runnable), the middleware already stands down automatically — no need
|
|
74
|
+
* to set this. See `start.external` for the whole-server switch.
|
|
75
|
+
*
|
|
76
|
+
* @default true (stands down automatically when the `ssr` dev environment isn't runnable)
|
|
77
|
+
*/
|
|
78
|
+
devMiddleware?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Path to a server-only module (resolved relative to the Vite root, like
|
|
81
|
+
* `start.document`) that the generated
|
|
82
|
+
* `virtual:solid-server-function-handler` module side-effect imports
|
|
83
|
+
* before configuring the runtime. A guaranteed pre-dispatch home for
|
|
84
|
+
* server-side registration — typically `configureServerFunctionsServer`
|
|
85
|
+
* calls whose config the app graph can't reliably install first, e.g. a
|
|
86
|
+
* router's single-flight collector:
|
|
87
|
+
*
|
|
88
|
+
* ```ts
|
|
89
|
+
* // src/server-config.ts
|
|
90
|
+
* import { configureServerFunctionsServer } from '@solidjs/web/server-functions/server';
|
|
91
|
+
* configureServerFunctionsServer({ collectFlightData: createFlightDataCollector(router) });
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* Because the module lives in the handler graph, it is evaluated before
|
|
95
|
+
* any dispatch on every surface — the dev middleware and the production
|
|
96
|
+
* handler alike — and is immune to the dev-restart race where
|
|
97
|
+
* registration living in the app graph only loads with the first page
|
|
98
|
+
* render (the handler graph loads before the first mutation). Config
|
|
99
|
+
* calls merge per key, so it composes with the plugin's own
|
|
100
|
+
* `configureServerFunctionsServer` call in the same module.
|
|
101
|
+
*
|
|
102
|
+
* @default undefined
|
|
103
|
+
*/
|
|
104
|
+
configure?: string;
|
|
105
|
+
/**
|
|
106
|
+
* Enable server components (experimental): `"use server"` functions that
|
|
107
|
+
* return a component. Responses for them are served over the
|
|
108
|
+
* server-function endpoint as streamed HTML that the client runtime
|
|
109
|
+
* applies in place of the boundary (instead of decoding it as data).
|
|
110
|
+
*
|
|
111
|
+
* The plugin's dispatch surfaces — the built-in dev middleware and the
|
|
112
|
+
* `virtual:solid-server-function-handler` module — install the response
|
|
113
|
+
* transform on the server runtime automatically, so this needs no
|
|
114
|
+
* per-request wiring or server code.
|
|
115
|
+
*
|
|
116
|
+
* Document SSR of server components (rendered inline at t=0 and adopted
|
|
117
|
+
* at boot with zero endpoint requests) needs three more pieces: the
|
|
118
|
+
* render must run with the server-component render plugin, the document
|
|
119
|
+
* must carry the bootstrap script, and the client must call
|
|
120
|
+
* `installServerComponents()` before hydrating. With SSR start mode (the
|
|
121
|
+
* main plugin's `start` option with `ssr: true`) and generated entries
|
|
122
|
+
* the plugin emits all three. With authored entries those pieces live in
|
|
123
|
+
* your entry files — import them from `@solidjs/web/frames` (see the
|
|
124
|
+
* README).
|
|
125
|
+
*
|
|
126
|
+
* All of this is pure codegen: when the option is off, no reference to
|
|
127
|
+
* the server-component runtime is emitted anywhere.
|
|
128
|
+
*
|
|
129
|
+
* @default false
|
|
130
|
+
*/
|
|
131
|
+
components?: boolean;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* The second parameter is internal wiring for the main plugin's
|
|
135
|
+
* `serverFunctions` option: the built-in dev middleware is only installed
|
|
136
|
+
* through that path, so meta-frameworks composing this factory directly
|
|
137
|
+
* (and dispatching to `handleServerFunctionRequest` themselves) never race
|
|
138
|
+
* it for the endpoint. On the main plugin's path the public
|
|
139
|
+
* `options.devMiddleware` (default true) can opt back out of it.
|
|
140
|
+
*/
|
|
141
|
+
export declare function serverFunctions(options?: ServerFunctionsOptions, internal?: {
|
|
142
|
+
devMiddleware?: boolean;
|
|
143
|
+
externalDevServer?: boolean;
|
|
144
|
+
ssrHandler?: string;
|
|
145
|
+
}): Plugin[];
|