-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathclient.js
More file actions
58 lines (56 loc) · 1.46 KB
/
client.js
File metadata and controls
58 lines (56 loc) · 1.46 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { directives, shimExportsPlugin } from "@vinxi/plugin-directives";
import { fileURLToPath } from "url";
import { chunkify } from "vinxi/lib/chunks";
import { normalize } from "vinxi/lib/path";
import { CLIENT_REFERENCES_MANIFEST } from "./constants.js";
export function client({
runtime = normalize(
fileURLToPath(new URL("./socket/plugin/client-runtime.js", import.meta.url))
),
manifest = CLIENT_REFERENCES_MANIFEST,
} = {}) {
const serverModules = new Set();
const clientModules = new Set();
return [
directives({
hash: chunkify,
runtime,
transforms: [
shimExportsPlugin({
runtime: {
module: runtime,
function: "createServerReference",
},
onModuleFound: (mod) => {
serverModules.add(mod);
},
hash: chunkify,
apply: (code, id, options) => {
return !options.ssr;
},
pragma: "use socket",
}),
],
onReference(type, reference) {
if (type === "server") {
serverModules.add(reference);
} else {
clientModules.add(reference);
}
},
}),
{
name: "references-manifest",
generateBundle() {
this.emitFile({
fileName: manifest,
type: "asset",
source: JSON.stringify({
server: [...serverModules],
client: [...clientModules],
}),
});
},
},
];
}