From 3c71166b4d4beac1bc761a282d6a55ca7d0e518f Mon Sep 17 00:00:00 2001 From: leeing <372711472@qq.com> Date: Tue, 23 Jul 2024 15:10:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20vue=20vite.config.js=20?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=20react-virtualized=20=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vue/vite.config.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/vue/vite.config.ts b/vue/vite.config.ts index 18bd037..c05c456 100644 --- a/vue/vite.config.ts +++ b/vue/vite.config.ts @@ -3,10 +3,32 @@ import { fileURLToPath, URL } from "node:url"; import { defineConfig } from "vite"; import vue from "@vitejs/plugin-vue"; import vueJsx from "@vitejs/plugin-vue-jsx"; +import * as path from 'path'; +import * as fs from 'fs'; + +// 解决 react-virtualized 的一个历史遗留问题,参考 issue:https://github.com/bvaughn/react-virtualized/issues/1722 +const WRONG_CODE = `import { bpfrpt_proptype_WindowScroller } from "../WindowScroller.js";`; + +function reactVirtualized() { + return { + name: 'my:react-virtualized', + 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); + }, + }; +} // https://vitejs.dev/config/ export default defineConfig({ - plugins: [vue(), vueJsx()], + plugins: [vue(), vueJsx(), reactVirtualized()], resolve: { alias: { "@": fileURLToPath(new URL("./src", import.meta.url)),