之前接兼职用vite+vue的时候就出现过
这次用vite5+react给公司写了一个静态页面打包之后,
打开dist文件中的index.html是空白
F12查看后是跨域报错
解决方法如下:
npm install --save-dev @vitejs/plugin-legacy
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import legacy from "@vitejs/plugin-legacy";
// https://vitejs.dev/config/
export default defineConfig({
base: "./",
plugins: [
react(),
legacy({
targets: ["ie>=11"],
additionalLegacyPolyfills: ["regenerator-runtime/runtime"],
}),
],
});