npm i?@vitejs/plugin-legacy?core-js/stable?regenerator-runtime/runtime
vite.config.ts 代碼
import { defineConfig} from 'vite'
import react from '@vitejs/plugin-react'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
import legacy from '@vitejs/plugin-legacy';
export default defineConfig(() => {
? return {
? ? plugins: [react(), nodePolyfills(),legacy({
? ? ? targets: ['defaults', 'not IE 11', 'last 2 versions', '> 1%', 'Android >= 4.4'],
? ? ? additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
? ? ? modernPolyfills: true
? ? })],
? ? css: {
? ? ? preprocessorOptions: {
? ? ? ? scss: {
? ? ? ? ? api: 'modern-compiler'
? ? ? ? }
? ? ? }
? ? },
? ? build: {
? ? ? minify: 'terser'
? ? }
? }
})
main.tsx 引入
import 'core-js/stable';
import 'regenerator-runtime/runtime';