-
-
Notifications
You must be signed in to change notification settings - Fork 882
Expand file tree
/
Copy pathvite.config.ts
More file actions
44 lines (41 loc) · 1.57 KB
/
Copy pathvite.config.ts
File metadata and controls
44 lines (41 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { defineConfig, type Plugin } from "vite";
import { nitro } from "nitro/vite";
/**
* Simulates an asset-collecting plugin (e.g. vite-plugin-solid's `?assets`
* crawl) that transforms a module's dependencies as a side effect of
* transforming the module itself. This repopulates the dependency's
* `transformResult` on the Vite side before the reloading dev worker's
* module runner re-fetches it, so `fetchModule` answers `{cache: true}` —
* the runner then reuses its stale evaluation unless the dev worker cleared
* its evaluated modules when reloading.
*/
function depCrawler(): Plugin {
return {
name: "test:dep-crawler",
async transform(_code, id) {
if (id.endsWith("api/crawled.ts") && this.environment.mode === "dev") {
await this.environment.transformRequest("/dep.ts");
}
},
};
}
/**
* Simulates a framework plugin that hard-invalidates the whole server module
* graph on edits (a common workaround for SSR staleness). Hard invalidation
* makes transform hooks re-run — which is what lets `depCrawler` above
* repopulate `dep.ts`'s transform during the reload. Scoped to `dep.ts`
* edits so the other HMR tests are unaffected.
*/
function serverGraphInvalidator(): Plugin {
return {
name: "test:server-graph-invalidator",
hotUpdate({ file }) {
if (file.endsWith("dep.ts") && this.environment.config.consumer !== "client") {
this.environment.moduleGraph.invalidateAll();
}
},
};
}
export default defineConfig({
plugins: [nitro({ serverDir: "./" }), depCrawler(), serverGraphInvalidator()],
});