From 79345f7ff3907380e48b0935e14fc64ee145b786 Mon Sep 17 00:00:00 2001 From: Puyodead1 Date: Tue, 3 Oct 2023 17:13:34 -0400 Subject: [PATCH] a --- vite.config.ts | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/vite.config.ts b/vite.config.ts index 30df716..8ad514b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,8 +1,9 @@ import replace from "@rollup/plugin-replace"; import react from "@vitejs/plugin-react"; -import { readFileSync } from "fs"; +import fs, { readFileSync } from "fs"; import { internalIpV4 } from "internal-ip"; -import { resolve } from "path"; +import path, { resolve } from "path"; +import type { Plugin } from "vite"; import { defineConfig } from "vite"; import { chunkSplitPlugin } from "vite-plugin-chunk-split"; import cleanPlugin from "vite-plugin-clean"; @@ -49,6 +50,7 @@ const mobile = !!/android|ios/.exec(process.env.TAURI_PLATFORM); export default defineConfig(async () => ({ plugins: [ cleanPlugin(), + reactVirtualized(), react(), svgr(), chunkSplitPlugin({ @@ -100,3 +102,30 @@ export default defineConfig(async () => ({ }, }, })); + +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 = path.join( + "node_modules", + "react-virtualized", + "dist", + "es", + "WindowScroller", + "utils", + "onScroll.js", + ); + + const code = fs.readFileSync(file, "utf-8"); + const modified = code.replace(WRONG_CODE, ""); + fs.writeFileSync(file, modified); + }, + }; +}