-
Notifications
You must be signed in to change notification settings - Fork 3
/
vite.config.ts
39 lines (37 loc) · 1.24 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
import react from "@vitejs/plugin-react";
//import { defineConfig } from "vite";
import { defineConfig } from "vitest/config";
import type { Plugin } from "vite";
import fs from "fs";
import path from "path";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), reactVirtualized()],
test: {
globals: true,
environment: "jsdom",
setupFiles: ["./tests/setup.ts"]
},
build: {
outDir: "./build"
}
});
const WRONG_CODE = `import { bpfrpt_proptype_WindowScroller } from "../WindowScroller.js";`;
export function reactVirtualized(): Plugin {
return {
name: "flat:react-virtualized",
// Note: we cannot use the `transform` hook here
// because libraries are pre-bundled in vite directly,
// plugins aren't able to hack that step currently.
// so instead we manually edit the file in node_modules.
// all we need is to find the timing before pre-bundling.
configResolved() {
const file = require
.resolve("react-virtualized")
.replace(path.join("dist", "commonjs", "index.js"), path.join("dist", "es", "WindowScroller", "utils", "onScroll.js"));
const code = fs.readFileSync(file, "utf-8");
const modified = code.replace(WRONG_CODE, "");
fs.writeFileSync(file, modified);
}
};
}