fix: 优化浏览器兼容策略

This commit is contained in:
landaiqing
2024-05-06 01:07:14 +08:00
parent feb965b11d
commit c4bd8f6be0
3 changed files with 171 additions and 187 deletions

View File

@@ -1,27 +0,0 @@
{
"plugins": [
[
"@babel/plugin-transform-runtime",
{
"corejs": 3
}
]
],
"presets": [
[
"@babel/preset-env",
{
"targets": {
"ie": "11",
"chrome": "58",
"safari": "11.1",
"firefox": "63",
"edge": "16"
},
"corejs": 3,
"useBuiltIns": "usage",
"modules": false
}
]
]
}

View File

@@ -6,8 +6,6 @@ import routeConfig from './router'
import 'virtual:svg-icons-register'
import { Provider as MobxProvider } from 'mobx-react'
import { RootStore } from '@/store'
import 'core-js';
import 'regenerator-runtime/runtime';
const router = createBrowserRouter(routeConfig)
ReactDOM.createRoot(document.getElementById('root')!).render(
// <React.StrictMode>

View File

@@ -1,26 +1,35 @@
import {defineConfig, loadEnv} from 'vite'
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import {resolve} from 'path'
import { resolve } from 'path'
// icons plugin
import {createSvgIconsPlugin} from 'vite-plugin-svg-icons'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import * as path from 'path'
import imagemin from 'unplugin-imagemin/vite'
import viteCompression from 'vite-plugin-compression'
import {createHtmlPlugin} from 'vite-plugin-html'
import { createHtmlPlugin } from 'vite-plugin-html'
import legacy from '@vitejs/plugin-legacy'
import postcssPresetEnv from 'postcss-preset-env'
import autoprefixer from 'autoprefixer'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
//配置参数
export default defineConfig(({mode}) => {
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd())
return {
base: '/',
plugins: [
react(),
legacy({
targets: ['ie >= 11', 'chrome 52', 'Chrome > 70', 'Safari 12.1', 'last 2 versions and since 2018 and > 0.5%', 'iOS >= 9','Android >= 4.4','last 2 versions'],
targets: [
'ie >= 11',
'chrome 52',
'Chrome > 70',
'Safari 12.1',
'last 2 versions and since 2018 and > 0.5%',
'iOS >= 9',
'Android >= 4.4',
'last 2 versions',
],
additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
renderLegacyChunks: true,
polyfills: [
@@ -40,9 +49,13 @@ export default defineConfig(({mode}) => {
'es.object.to-string',
'web.dom-collections.for-each',
'esnext.global-this',
'esnext.string.match-all'
'esnext.string.match-all',
],
modernPolyfills: [
'es.promise.all-settled',
'es.object.entries',
'es.string.replace-all',
],
modernPolyfills: ['es.promise.all-settled', 'es.object.entries', 'es.string.replace-all'],
}),
// 修改 icons 相关配置
createSvgIconsPlugin({
@@ -71,9 +84,9 @@ export default defineConfig(({mode}) => {
},
},
conversion: [
{from: 'jpeg', to: 'webp'},
{from: 'png', to: 'webp'},
{from: 'JPG', to: 'jpeg'},
{ from: 'jpeg', to: 'webp' },
{ from: 'png', to: 'webp' },
{ from: 'JPG', to: 'jpeg' },
],
}),
viteCompression({