-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.postbuild.ts
41 lines (40 loc) · 1.43 KB
/
vite.postbuild.ts
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
import { PluginOption } from "vite";
import { WebSocket } from "ws";
export function notifyEditorAfterBuildPlugin(): PluginOption {
return {
name: "postbuild-notify-editor",
closeBundle: () =>
new Promise<void>((resolve) => {
if (
process.env.WEB_COMPONENT_NAME &&
process.env.WEB_COMPONENT_NAME != "profile-cloud-dev"
) {
resolve();
}
let timeout = setTimeout(() => {
console.log("No connection to Editor, closing websocket connection");
ws.close();
resolve();
}, 3000);
let ws = new WebSocket("ws://localhost:9000");
ws.on("open", () => {
ws.send(
JSON.stringify({
type: "developer-package",
event: "components-build-complete",
id: "profile-cloud",
rootPath: __dirname
})
);
ws.close();
clearTimeout(timeout);
resolve();
});
ws.on("error", (err) => {
console.error(err);
clearTimeout(timeout);
resolve();
});
})
};
}