-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
67 lines (62 loc) · 1.86 KB
/
vite.config.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import react from "@vitejs/plugin-react";
import { resolve } from "path";
import { defineConfig, ModuleNode, Plugin } from "vite";
import dts from "vite-plugin-dts";
// storybook uses vite hmr in this case. When f.ex. changing the createEvent file
// the StorySetup.ts file will be HMRed, but not the event bus. This will cause the events to be executed
// twice, causing an error, since duplicated event names are not allowed. This should only happen in dev
// HMR mode and never in prod (unless there are actually several events with the same name).
// To circumvent, the event bus is added to the hmr modules if it is not already, but is imported in any module
// that is HMRed
// ?? changes to logger still cause the HMR issue TBD
const hmrCompatibleEvents: () => Plugin = () => ({
name: "HmrCompatibleEvents",
handleHotUpdate(ctx) {
let isInHmrModules = false;
let importedBus: ModuleNode | null = null;
ctx.modules.forEach((module) => {
if (module.url.endsWith("event-bus/index.ts")) isInHmrModules = true;
module.importedModules.forEach((imp) => {
if (imp.url.endsWith("event-bus/index.ts")) importedBus = imp;
});
});
const toUpdateModules = !isInHmrModules
? !!importedBus
? [...ctx.modules, importedBus]
: ctx.modules
: ctx.modules;
return toUpdateModules;
},
});
export default defineConfig((env) => ({
publicDir: false,
plugins: [
hmrCompatibleEvents(),
react(),
dts({
include: ["src/"],
exclude: ["src/stories"],
}),
],
build: {
lib: {
entry: resolve(__dirname, "src/index.tsx"),
name: "lucid-events",
fileName: "index",
},
rollupOptions: {
external: ["react", "react-dom", "@hpcc-js/wasm/graphviz", /^@radix-ui.*/],
output: {
globals: {
react: "React",
"react-dom": "ReactDOM",
},
},
},
},
test: {
globals: true,
environment: "jsdom",
setupFiles: "src/setup-tests.ts",
},
}));